mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
feat: small file is unrequired to verity to download.
This commit is contained in:
@@ -702,20 +702,32 @@ function FileTile({ file }: { file: RFile }) {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className={"flex flex-row items-center"}>
|
<div className={"flex flex-row items-center"}>
|
||||||
<button
|
{
|
||||||
ref={buttonRef}
|
file.size > 10 * 1024 * 1024 ? (
|
||||||
className={"btn btn-primary btn-soft btn-square"}
|
<button
|
||||||
onClick={() => {
|
ref={buttonRef}
|
||||||
if (!app.cloudflareTurnstileSiteKey) {
|
className={"btn btn-primary btn-soft btn-square"}
|
||||||
const link = network.getFileDownloadLink(file.id, "");
|
onClick={() => {
|
||||||
window.open(link, "_blank");
|
if (!app.cloudflareTurnstileSiteKey) {
|
||||||
} else {
|
const link = network.getFileDownloadLink(file.id, "");
|
||||||
showPopup(<CloudflarePopup file={file} />, buttonRef.current!);
|
window.open(link, "_blank");
|
||||||
}
|
} else {
|
||||||
}}
|
showPopup(<CloudflarePopup file={file} />, buttonRef.current!);
|
||||||
>
|
}
|
||||||
<MdOutlineDownload size={24} />
|
}}
|
||||||
</button>
|
>
|
||||||
|
<MdOutlineDownload size={24} />
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<a
|
||||||
|
href={network.getFileDownloadLink(file.id, "")}
|
||||||
|
target="_blank"
|
||||||
|
className={"btn btn-primary btn-soft btn-square"}
|
||||||
|
>
|
||||||
|
<MdOutlineDownload size={24} />
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -20,8 +20,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
blockSize = 4 * 1024 * 1024 // 4MB
|
blockSize = 4 * 1024 * 1024 // 4MB
|
||||||
storageKeyUnavailable = "storage_key_unavailable" // Placeholder for unavailable storage key
|
storageKeyUnavailable = "storage_key_unavailable" // Placeholder for unavailable storage key
|
||||||
|
MinUnrequireVerifyFileSize = 10 * 1024 * 1024 // 10MB
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUploadingSize() int64 {
|
func getUploadingSize() int64 {
|
||||||
@@ -387,15 +388,6 @@ 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) (string, string, error) {
|
||||||
passed, err := verifyCfToken(cfToken)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to verify cf token: ", err)
|
|
||||||
return "", "", model.NewRequestError("failed to verify cf token")
|
|
||||||
}
|
|
||||||
if !passed {
|
|
||||||
log.Info("cf token verification failed")
|
|
||||||
return "", "", model.NewRequestError("cf token verification failed")
|
|
||||||
}
|
|
||||||
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)
|
||||||
@@ -405,6 +397,16 @@ func DownloadFile(fid, cfToken string) (string, string, error) {
|
|||||||
return "", "", model.NewRequestError("file is not available, please try again later")
|
return "", "", model.NewRequestError("file is not available, please try again later")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
passed, err := verifyCfToken(cfToken)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to verify cf token: ", err)
|
||||||
|
return "", "", model.NewRequestError("failed to verify cf token")
|
||||||
|
}
|
||||||
|
if !passed && file.Size > MinUnrequireVerifyFileSize {
|
||||||
|
log.Info("cf token verification failed")
|
||||||
|
return "", "", model.NewRequestError("cf token verification failed")
|
||||||
|
}
|
||||||
|
|
||||||
if file.StorageID == nil {
|
if file.StorageID == nil {
|
||||||
if file.RedirectUrl != "" {
|
if file.RedirectUrl != "" {
|
||||||
err := dao.AddResourceDownloadCount(file.ResourceID)
|
err := dao.AddResourceDownloadCount(file.ResourceID)
|
||||||
|
@@ -28,6 +28,9 @@ func verifyCfToken(cfToken string) (bool, error) {
|
|||||||
if config.CloudflareTurnstileSecretKey() == "" {
|
if config.CloudflareTurnstileSecretKey() == "" {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
if cfToken == "" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
data, _ := json.Marshal(map[string]string{
|
data, _ := json.Marshal(map[string]string{
|
||||||
"secret": config.CloudflareTurnstileSecretKey(),
|
"secret": config.CloudflareTurnstileSecretKey(),
|
||||||
|
Reference in New Issue
Block a user