properly reject emoji file names for dropbox

This commit is contained in:
fyears
2022-04-16 11:36:04 +08:00
parent 9a4dd0186d
commit cb7a372b69
3 changed files with 97 additions and 14 deletions
+29
View File
@@ -3,6 +3,7 @@ import * as path from "path";
import { base32, base64url } from "rfc4648";
import XRegExp from "xregexp";
import emojiRegex from "emoji-regex";
import { log } from "./moreOnLog";
@@ -162,6 +163,34 @@ export const isVaildText = (a: string) => {
);
};
/**
* Use regex to detect a text contains emoji or not.
* @param a
* @returns
*/
export const hasEmojiInText = (a: string) => {
const regex = emojiRegex();
return regex.test(a);
};
/**
* Convert the headers to a normal object.
* @param h
* @param toLower
* @returns
*/
export const headersToRecord = (h: Headers, toLower: boolean = true) => {
const res: Record<string, string> = {};
h.forEach((v, k) => {
if (toLower) {
res[k.toLowerCase()] = v;
} else {
res[k] = v;
}
});
return res;
};
/**
* If input is already a folder, returns it as is;
* And if input is a file, returns its direname.