Format & lint
This commit is contained in:
parent
fefac224b0
commit
7f62273e72
1 changed files with 2149 additions and 1258 deletions
|
|
@ -8,16 +8,10 @@
|
|||
export const CONFLICT_PATH_REGEX =
|
||||
/(?:^|\/)conflict-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}-[^/]*$/u;
|
||||
|
||||
|
||||
const CONFLICT_PREFIX_LEN = "conflict-".length + 36 + 1;
|
||||
const MAX_SEGMENT_BYTES = 255;
|
||||
const MAX_ORIGINAL_BYTES = MAX_SEGMENT_BYTES - CONFLICT_PREFIX_LEN - 4;
|
||||
|
||||
export function buildConflictFileName(fileName: string): string {
|
||||
const safeName = truncateFileNameToByteLimit(fileName, MAX_ORIGINAL_BYTES);
|
||||
return `conflict-${crypto.randomUUID()}-${safeName}`;
|
||||
}
|
||||
|
||||
function truncateFileNameToByteLimit(
|
||||
fileName: string,
|
||||
maxBytes: number
|
||||
|
|
@ -34,7 +28,9 @@ function truncateFileNameToByteLimit(
|
|||
const extensionBytes = encoder.encode(extension).byteLength;
|
||||
const stemBudget = Math.max(0, maxBytes - extensionBytes);
|
||||
|
||||
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
||||
const segmenter = new Intl.Segmenter(undefined, {
|
||||
granularity: "grapheme"
|
||||
});
|
||||
let truncatedStem = "";
|
||||
let usedBytes = 0;
|
||||
for (const { segment } of segmenter.segment(stem)) {
|
||||
|
|
@ -45,3 +41,8 @@ function truncateFileNameToByteLimit(
|
|||
}
|
||||
return truncatedStem + extension;
|
||||
}
|
||||
|
||||
export function buildConflictFileName(fileName: string): string {
|
||||
const safeName = truncateFileNameToByteLimit(fileName, MAX_ORIGINAL_BYTES);
|
||||
return `conflict-${crypto.randomUUID()}-${safeName}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue