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 {
|
func downloadFile(c fiber.Ctx) error {
|
||||||
cfToken := c.Query("cf_token")
|
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 {
|
if err != nil {
|
||||||
return err
|
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.
|
// 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)
|
file, err := dao.GetFile(fid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("failed to get file: ", err)
|
log.Error("failed to get file: ", err)
|
||||||
@@ -436,9 +436,11 @@ func DownloadFile(fid, cfToken string) (string, string, error) {
|
|||||||
return "", "", model.NewInternalServerError("failed to download file from storage")
|
return "", "", model.NewInternalServerError("failed to download file from storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dao.AddResourceDownloadCount(file.ResourceID)
|
if isRealUser {
|
||||||
if err != nil {
|
err = dao.AddResourceDownloadCount(file.ResourceID)
|
||||||
log.Errorf("failed to add resource download count: %v", err)
|
if err != nil {
|
||||||
|
log.Errorf("failed to add resource download count: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return path, file.Filename, nil
|
return path, file.Filename, nil
|
||||||
|
Reference in New Issue
Block a user