mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-26 12:15:38 +03:00
Fix attachment pruning logging; .mp4 extension issue
This commit is contained in:
parent
44a9509cd6
commit
b5183612be
@ -71,13 +71,12 @@ func (c *fileCache) Write(id string, in io.Reader, limiters ...*util.Limiter) (i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *fileCache) Remove(ids ...string) error {
|
func (c *fileCache) Remove(ids ...string) error {
|
||||||
var firstErr error
|
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
if err := c.removeFile(id); err != nil {
|
if !fileIDRegex.MatchString(id) {
|
||||||
if firstErr == nil {
|
return errInvalidFileID
|
||||||
firstErr = err // Continue despite error; we want to delete as many as we can
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
file := filepath.Join(c.dir, id)
|
||||||
|
_ = os.Remove(file) // Best effort delete
|
||||||
}
|
}
|
||||||
size, err := dirSize(c.dir)
|
size, err := dirSize(c.dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -86,15 +85,7 @@ func (c *fileCache) Remove(ids ...string) error {
|
|||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.totalSizeCurrent = size
|
c.totalSizeCurrent = size
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
return firstErr
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func (c *fileCache) removeFile(id string) error {
|
|
||||||
if !fileIDRegex.MatchString(id) {
|
|
||||||
return errInvalidFileID
|
|
||||||
}
|
|
||||||
file := filepath.Join(c.dir, id)
|
|
||||||
return os.Remove(file)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fileCache) Size() int64 {
|
func (c *fileCache) Size() int64 {
|
||||||
|
@ -173,6 +173,8 @@ func ExtensionByType(contentType string) string {
|
|||||||
switch contentType {
|
switch contentType {
|
||||||
case "image/jpeg":
|
case "image/jpeg":
|
||||||
return ".jpg"
|
return ".jpg"
|
||||||
|
case "video/mp4":
|
||||||
|
return ".mp4"
|
||||||
default:
|
default:
|
||||||
exts, err := mime.ExtensionsByType(contentType)
|
exts, err := mime.ExtensionsByType(contentType)
|
||||||
if err == nil && len(exts) > 0 && extRegex.MatchString(exts[0]) {
|
if err == nil && len(exts) > 0 && extRegex.MatchString(exts[0]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user