Revert "fix: sanitize backup file names for windows"
This reverts commit 9d017b5745.
This commit is contained in:
@@ -7,25 +7,21 @@ import {
|
|||||||
PayloadContent,
|
PayloadContent,
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
|
|
||||||
function sanitizeFileName(name: string) {
|
function zippableTxtName(name: string, suffix = ""): string {
|
||||||
return name
|
const sanitizedName = name
|
||||||
.replace(/\//g, '')
|
.replace(/\//g, '')
|
||||||
.replace(/\\+/g, '')
|
.replace(/\\+/g, '')
|
||||||
.replace(/:/g, ' ')
|
.replace(/:/g, ' ')
|
||||||
.replace(/\|/g, ' ')
|
.replace(/\./g, ' ');
|
||||||
.replace(/\./g, ' ');
|
const nameEnd = suffix + ".txt";
|
||||||
}
|
|
||||||
|
|
||||||
function zippableTxtName(name: string, suffix = ''): string {
|
|
||||||
const sanitizedName = sanitizeFileName(name);
|
|
||||||
const nameEnd = suffix + '.txt';
|
|
||||||
const maxFileNameLength = 255;
|
const maxFileNameLength = 255;
|
||||||
return sanitizedName.slice(0, maxFileNameLength - nameEnd.length) + nameEnd;
|
return sanitizedName.slice(0, maxFileNameLength - nameEnd.length) + nameEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ArchiveManager {
|
export class ArchiveManager {
|
||||||
private readonly application: WebApplication;
|
|
||||||
private textFile?: string;
|
private readonly application: WebApplication
|
||||||
|
private textFile?: string
|
||||||
|
|
||||||
constructor(application: WebApplication) {
|
constructor(application: WebApplication) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
@@ -40,9 +36,10 @@ export class ArchiveManager {
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const blobData = new Blob([JSON.stringify(data, null, 2)], {
|
const blobData = new Blob(
|
||||||
type: 'text/json',
|
[JSON.stringify(data, null, 2)],
|
||||||
});
|
{ type: 'text/json' }
|
||||||
|
);
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
this.downloadData(
|
this.downloadData(
|
||||||
blobData,
|
blobData,
|
||||||
@@ -88,18 +85,21 @@ export class ArchiveManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async downloadZippedDecryptedItems(data: BackupFile) {
|
private async downloadZippedDecryptedItems(
|
||||||
|
data: BackupFile
|
||||||
|
) {
|
||||||
await this.loadZip();
|
await this.loadZip();
|
||||||
const items = data.items;
|
const items = data.items;
|
||||||
this.zip.createWriter(
|
this.zip.createWriter(
|
||||||
new this.zip.BlobWriter('application/zip'),
|
new this.zip.BlobWriter('application/zip'),
|
||||||
async (zipWriter: any) => {
|
async (zipWriter: any) => {
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
const blob = new Blob([JSON.stringify(data, null, 2)], {
|
const blob = new Blob(
|
||||||
type: 'text/plain',
|
[JSON.stringify(data, null, 2)],
|
||||||
});
|
{ type: 'text/plain' }
|
||||||
|
);
|
||||||
const fileName = zippableTxtName(
|
const fileName = zippableTxtName(
|
||||||
'Standard Notes Backup and Import File'
|
'Standard Notes Backup and Import File.txt'
|
||||||
);
|
);
|
||||||
zipWriter.add(fileName, new this.zip.BlobReader(blob), resolve);
|
zipWriter.add(fileName, new this.zip.BlobReader(blob), resolve);
|
||||||
});
|
});
|
||||||
@@ -120,8 +120,7 @@ export class ArchiveManager {
|
|||||||
name = '';
|
name = '';
|
||||||
}
|
}
|
||||||
const blob = new Blob([contents], { type: 'text/plain' });
|
const blob = new Blob([contents], { type: 'text/plain' });
|
||||||
const fileName =
|
const fileName = `Items/${item.content_type}/` +
|
||||||
`Items/${sanitizeFileName(item.content_type)}/` +
|
|
||||||
zippableTxtName(name, `-${item.uuid.split('-')[0]}`);
|
zippableTxtName(name, `-${item.uuid.split('-')[0]}`);
|
||||||
zipWriter.add(fileName, new this.zip.BlobReader(blob), () => {
|
zipWriter.add(fileName, new this.zip.BlobReader(blob), () => {
|
||||||
index++;
|
index++;
|
||||||
@@ -139,9 +138,7 @@ export class ArchiveManager {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
nextFile();
|
nextFile();
|
||||||
},
|
}, onerror);
|
||||||
onerror
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private hrefForData(data: Blob) {
|
private hrefForData(data: Blob) {
|
||||||
|
|||||||
Reference in New Issue
Block a user