fix: TypeScript errors after upgrading SNJS

This commit is contained in:
Baptiste Grob
2021-01-11 17:42:35 +01:00
parent ff85c9c640
commit e1f590f2f0
3 changed files with 30 additions and 32 deletions

View File

@@ -7,7 +7,7 @@
"rules": { "rules": {
"standard/no-callback-literal": 0, // Disable this as we have too many callbacks relying on literals "standard/no-callback-literal": 0, // Disable this as we have too many callbacks relying on literals
"no-throw-literal": 0, "no-throw-literal": 0,
"no-console": "warn", "no-console": "off",
"semi": 1, "semi": 1,
"camelcase": "warn" "camelcase": "warn"
}, },

View File

@@ -1,5 +1,5 @@
import { WebApplication } from '@/ui_models/application'; import { WebApplication } from '@/ui_models/application';
import { EncryptionIntent, ProtectedAction, SNItem, ContentType, SNNote } from '@standardnotes/snjs'; import { EncryptionIntent, ProtectedAction, SNItem, ContentType, SNNote, BackupFile } from '@standardnotes/snjs';
function zippableTxtName(name: string, suffix = ""): string { function zippableTxtName(name: string, suffix = ""): string {
const sanitizedName = name const sanitizedName = name
@@ -22,22 +22,27 @@ export class ArchiveManager {
} }
public async downloadBackup(encrypted: boolean) { public async downloadBackup(encrypted: boolean) {
const items = this.application.allItems();
const run = async () => { const run = async () => {
// download in Standard Notes format
const intent = encrypted const intent = encrypted
? EncryptionIntent.FileEncrypted ? EncryptionIntent.FileEncrypted
: EncryptionIntent.FileDecrypted; : EncryptionIntent.FileDecrypted;
const data = await this.application.createBackupFile(intent);
if (!data) {
return;
}
const blobData = new Blob(
[JSON.stringify(data, null, 2)],
{ type: 'text/json' }
);
if (encrypted) { if (encrypted) {
const data = await this.itemsData(items, intent);
this.downloadData( this.downloadData(
data!, blobData,
`Standard Notes Encrypted Backup and Import File - ${this.formattedDate()}.txt` `Standard Notes Encrypted Backup and Import File - ${this.formattedDate()}.txt`
); );
} else { } else {
/** download as zipped plain text files */ /** download as zipped plain text files */
this.downloadZippedItems(items); this.downloadZippedDecryptedItems(data);
} }
}; };
@@ -65,15 +70,6 @@ export class ArchiveManager {
return string; return string;
} }
private async itemsData(items: SNItem[], intent: EncryptionIntent) {
const data = await this.application.createBackupFile(items, intent);
if (!data) {
return undefined;
}
const blobData = new Blob([data], { type: 'text/json' });
return blobData;
}
private get zip() { private get zip() {
return (window as any).zip; return (window as any).zip;
} }
@@ -95,17 +91,19 @@ export class ArchiveManager {
}); });
} }
private async downloadZippedItems( private async downloadZippedDecryptedItems(
items: SNItem[] data: BackupFile
) { ) {
await this.loadZip(); await this.loadZip();
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) => {
const data = await this.application.createBackupFile(items, EncryptionIntent.FileDecrypted);
await new Promise((resolve) => { await new Promise((resolve) => {
const blob = new Blob([data!], { type: 'text/plain' }); const blob = new Blob(
[JSON.stringify(data, null, 2)],
{ type: 'text/plain' }
);
const fileName = zippableTxtName( const fileName = zippableTxtName(
'Standard Notes Backup and Import File.txt' 'Standard Notes Backup and Import File.txt'
); );

View File

@@ -9,8 +9,8 @@ import { Bridge } from './bridge';
type UpdateObserverCallback = (component: SNComponent) => void type UpdateObserverCallback = (component: SNComponent) => void
type ComponentActivationCallback = (payload: PurePayload) => void type ComponentActivationCallback = (payload: PurePayload) => void
type ComponentActivationObserver = { type ComponentActivationObserver = {
id: string, id: string;
callback: ComponentActivationCallback callback: ComponentActivationCallback;
} }
export class DesktopManager extends ApplicationService { export class DesktopManager extends ApplicationService {
@@ -19,8 +19,9 @@ export class DesktopManager extends ApplicationService {
$timeout: ng.ITimeoutService $timeout: ng.ITimeoutService
componentActivationObservers: ComponentActivationObserver[] = [] componentActivationObservers: ComponentActivationObserver[] = []
updateObservers: { updateObservers: {
callback: UpdateObserverCallback callback: UpdateObserverCallback;
}[] = [] }[] = [];
isDesktop = isDesktopApplication(); isDesktop = isDesktopApplication();
dataLoaded = false dataLoaded = false
@@ -187,12 +188,11 @@ export class DesktopManager extends ApplicationService {
}); });
} }
desktop_requestBackupFile() { async desktop_requestBackupFile() {
return this.application!.createBackupFile( const data = this.application!.createBackupFile(EncryptionIntent.FileEncrypted);
undefined, if (data) {
undefined, return JSON.stringify(data, null, 2);
true }
);
} }
desktop_didBeginBackup() { desktop_didBeginBackup() {