[add] document view, [add] html sanitization, [add] google books metadata enrichment, [improve] db query performance
This commit is contained in:
@@ -335,12 +335,12 @@ func (api *API) addDocuments(c *gin.Context) {
|
||||
for _, doc := range rNewDocs.Documents {
|
||||
doc, err := qtx.UpsertDocument(api.DB.Ctx, database.UpsertDocumentParams{
|
||||
ID: doc.ID,
|
||||
Title: doc.Title,
|
||||
Author: doc.Author,
|
||||
Series: doc.Series,
|
||||
Title: api.sanitizeInput(doc.Title),
|
||||
Author: api.sanitizeInput(doc.Author),
|
||||
Series: api.sanitizeInput(doc.Series),
|
||||
SeriesIndex: doc.SeriesIndex,
|
||||
Lang: doc.Lang,
|
||||
Description: doc.Description,
|
||||
Lang: api.sanitizeInput(doc.Lang),
|
||||
Description: api.sanitizeInput(doc.Description),
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("[addDocuments] UpsertDocument DB Error:", err)
|
||||
@@ -605,6 +605,22 @@ func (api *API) downloadDocumentFile(c *gin.Context) {
|
||||
c.File(filePath)
|
||||
}
|
||||
|
||||
func (api *API) sanitizeInput(val any) *string {
|
||||
switch v := val.(type) {
|
||||
case *string:
|
||||
if v != nil {
|
||||
newString := api.HTMLPolicy.Sanitize(string(*v))
|
||||
return &newString
|
||||
}
|
||||
case string:
|
||||
if v != "" {
|
||||
newString := api.HTMLPolicy.Sanitize(string(v))
|
||||
return &newString
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getKeys[M ~map[K]V, K comparable, V any](m M) []K {
|
||||
r := make([]K, 0, len(m))
|
||||
for k := range m {
|
||||
|
||||
Reference in New Issue
Block a user