mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Download: Add Disabled, Originals, MediaRaw & MediaSidecar Flags #2234
Extends DownloadSettings with 4 additional options: - Name: File name pattern for downloaded files (existed) - Disabled: Disables downloads - Originals: Only download files stored in "originals" folder - MediaRaw: Include RAW image files - MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
This commit is contained in:
53
pkg/clean/sql.go
Normal file
53
pkg/clean/sql.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package clean
|
||||
|
||||
// SqlSpecial checks if the byte must be escaped/omitted in SQL.
|
||||
func SqlSpecial(b byte) (special bool, omit bool) {
|
||||
if b < 32 {
|
||||
return true, true
|
||||
}
|
||||
|
||||
switch b {
|
||||
case '"', '\'', '\\':
|
||||
return true, false
|
||||
default:
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
|
||||
// SqlString escapes a string for use in an SQL query.
|
||||
func SqlString(s string) string {
|
||||
var i int
|
||||
for i = 0; i < len(s); i++ {
|
||||
if found, _ := SqlSpecial(s[i]); found {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Return if no special characters were found.
|
||||
if i >= len(s) {
|
||||
return s
|
||||
}
|
||||
|
||||
b := make([]byte, 2*len(s)-i)
|
||||
|
||||
copy(b, s[:i])
|
||||
|
||||
j := i
|
||||
|
||||
for ; i < len(s); i++ {
|
||||
if special, omit := SqlSpecial(s[i]); omit {
|
||||
// Omit control characters.
|
||||
continue
|
||||
} else if special {
|
||||
// Escape other special characters.
|
||||
// see https://mariadb.com/kb/en/string-literals/
|
||||
b[j] = s[i]
|
||||
j++
|
||||
}
|
||||
|
||||
b[j] = s[i]
|
||||
j++
|
||||
}
|
||||
|
||||
return string(b[:j])
|
||||
}
|
||||
Reference in New Issue
Block a user