display files with cache image
This commit is contained in:
@@ -47,6 +47,17 @@ func (s *FileService) Upload(file *multipart.FileHeader) (*model.UploadResult, e
|
||||
|
||||
checksum := hex.EncodeToString(CreateSHA256Hash(data))
|
||||
|
||||
existing, err := s.queries.FindDuplicateByChecksum(context.Background(), checksum)
|
||||
if err == nil && existing.ID != "" {
|
||||
os.Remove(dst)
|
||||
return &model.UploadResult{
|
||||
ID: existing.ID,
|
||||
Name: existing.Name,
|
||||
Path: existing.StorageKey,
|
||||
MimeType: existing.MimeType,
|
||||
}, nil
|
||||
}
|
||||
|
||||
dbFile, err := s.queries.CreateFile(context.Background(), db.CreateFileParams{
|
||||
Name: file.Filename,
|
||||
MimeType: file.Header.Get("Content-Type"),
|
||||
@@ -280,6 +291,13 @@ func (s *FileService) GetBestThumbnail(fileID, preferredLabel string) *model.Thu
|
||||
return fallback
|
||||
}
|
||||
|
||||
func (s *FileService) FindDuplicatesByNameSize(name string, size int64) ([]db.FindDuplicatesByNameSizeRow, error) {
|
||||
return s.queries.FindDuplicatesByNameSize(context.Background(), db.FindDuplicatesByNameSizeParams{
|
||||
Name: name,
|
||||
Size: size,
|
||||
})
|
||||
}
|
||||
|
||||
func dbToModel(f db.File, dbTags []db.Tag) model.File {
|
||||
tags := make([]model.Tag, len(dbTags))
|
||||
for i, t := range dbTags {
|
||||
|
||||
@@ -9,12 +9,20 @@ import (
|
||||
)
|
||||
|
||||
type URLService struct {
|
||||
secret string
|
||||
serverHost string
|
||||
secret string
|
||||
serverHost string
|
||||
expiryDuration time.Duration
|
||||
}
|
||||
|
||||
func NewURLService(secret, serverHost string) *URLService {
|
||||
return &URLService{secret: secret, serverHost: serverHost}
|
||||
func NewURLService(secret, serverHost string, expiryMinutes int) *URLService {
|
||||
if expiryMinutes <= 0 {
|
||||
expiryMinutes = 60
|
||||
}
|
||||
return &URLService{
|
||||
secret: secret,
|
||||
serverHost: serverHost,
|
||||
expiryDuration: time.Duration(expiryMinutes) * time.Minute,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *URLService) sign(fileID string, expires int64) string {
|
||||
@@ -25,7 +33,7 @@ func (s *URLService) sign(fileID string, expires int64) string {
|
||||
}
|
||||
|
||||
func (s *URLService) GenerateDownloadURL(fileUUID string) string {
|
||||
expires := time.Now().Add(10 * time.Minute).Unix()
|
||||
expires := time.Now().Add(s.expiryDuration).Unix()
|
||||
sig := s.sign(fileUUID, expires)
|
||||
|
||||
return fmt.Sprintf(
|
||||
@@ -38,7 +46,7 @@ func (s *URLService) GenerateDownloadURL(fileUUID string) string {
|
||||
}
|
||||
|
||||
func (s *URLService) GenerateThumbnailURL(thumbUUID string) string {
|
||||
expires := time.Now().Add(10 * time.Minute).Unix()
|
||||
expires := time.Now().Add(s.expiryDuration).Unix()
|
||||
sig := s.sign(thumbUUID, expires)
|
||||
|
||||
return fmt.Sprintf(
|
||||
|
||||
Reference in New Issue
Block a user