Skip to content

fix(blob path): Random variables in blob save path be wrongly fixed #2741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2025

Conversation

YUDONGLING
Copy link
Member

No description provided.

@YUDONGLING
Copy link
Member Author

Fixed, as well as some problem in indent character. @HFO4

}

nameRule := policy.FileNameRule
nameRule = util.Replace(baseTable, nameRule)
nameRule = util.Replace(nameTable, nameRule)
nameRule = filepath.ToSlash(nameRule)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this? If it's working now, we'd better not change it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emm.. As now we ask the blob path to include at least one random item, but the check in frontend only in blob name but not include the base path.
Thus, in some storage policies which do not keep the name as download, some may set the base path like upload/{uid} but the blob name to be {uuid}/{org. name}. So i think maybe add a .ToSlash here will be better (though not support 😄)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, maybe another solution to be turn the two setting item into a single one full_blob_path, but this need update in database when upgrade version and i m not sure how to do that.
Or use another js function to check the validation of the base path+blob name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the frontend validation rule, as long as one of path/blob name contains random item, it will be fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. i will remove this.

@@ -785,24 +780,50 @@ func generateSavePath(policy *ent.StoragePolicy, req *fs.UploadRequest, user *en
"{second}": time.Now().Format("05"),
}

dynamicReplace := func(regPattern string, rule string) string {
re := regexp.MustCompile(regPattern)
return re.ReplaceAllStringFunc(rule, func(match string) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try to use regex to match and replace all available variables (as long as it's wrapped by { and })? Including those in fixedBaseTable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine. I'll update that later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. @HFO4

@HFO4 HFO4 merged commit 7654ce8 into cloudreve:master Aug 5, 2025
2 checks passed
@HFO4
Copy link
Member

HFO4 commented Aug 5, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants