mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
fix: handle cjk and special chars when slugifying (#2544)
This commit is contained in:
@@ -20,7 +20,20 @@ export const getPresignPostUrl = async (fileName: string, contentType: string, u
|
||||
// Get the basename and extension for the file
|
||||
const { name, ext } = path.parse(fileName);
|
||||
|
||||
let key = `${alphaid(12)}/${slugify(name)}${ext}`;
|
||||
let slugified = slugify(name);
|
||||
|
||||
// If the slugified name is empty or too long, generate a random string instead
|
||||
//
|
||||
// This is fine since we don't really need the filename in s3 since we store it
|
||||
// in the database and can always get the original filename from there.
|
||||
//
|
||||
// The slugified name can be empty when a string contains only CJK or other
|
||||
// special characters.
|
||||
if (slugified.length === 0 || slugified.length > 100) {
|
||||
slugified = alphaid(8);
|
||||
}
|
||||
|
||||
let key = `${alphaid(12)}/${slugified}${ext}`;
|
||||
|
||||
if (userId) {
|
||||
key = `${userId}/${key}`;
|
||||
|
||||
Reference in New Issue
Block a user