mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
enhance file download handling to track real users
This commit is contained in:
@@ -205,7 +205,7 @@ func deleteFile(c fiber.Ctx) error {
|
||||
|
||||
func downloadFile(c fiber.Ctx) error {
|
||||
cfToken := c.Query("cf_token")
|
||||
s, filename, err := service.DownloadFile(c.Params("id"), cfToken)
|
||||
s, filename, err := service.DownloadFile(c.Params("id"), cfToken, c.Locals("real_user") == true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -389,7 +389,7 @@ func GetFile(fid string) (*model.FileView, error) {
|
||||
}
|
||||
|
||||
// DownloadFile handles the file download request. Return a presigned URL or a direct file path.
|
||||
func DownloadFile(fid, cfToken string) (string, string, error) {
|
||||
func DownloadFile(fid, cfToken string, isRealUser bool) (string, string, error) {
|
||||
file, err := dao.GetFile(fid)
|
||||
if err != nil {
|
||||
log.Error("failed to get file: ", err)
|
||||
@@ -436,10 +436,12 @@ func DownloadFile(fid, cfToken string) (string, string, error) {
|
||||
return "", "", model.NewInternalServerError("failed to download file from storage")
|
||||
}
|
||||
|
||||
if isRealUser {
|
||||
err = dao.AddResourceDownloadCount(file.ResourceID)
|
||||
if err != nil {
|
||||
log.Errorf("failed to add resource download count: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return path, file.Filename, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user