Skip to content

Commit

Permalink
fix: TypeScript errors after upgrading SNJS
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Jan 11, 2021
1 parent ff85c9c commit e1f590f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"rules": {
"standard/no-callback-literal": 0, // Disable this as we have too many callbacks relying on literals
"no-throw-literal": 0,
"no-console": "warn",
"no-console": "off",
"semi": 1,
"camelcase": "warn"
},
Expand Down
40 changes: 19 additions & 21 deletions app/assets/javascripts/services/archiveManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 {
const sanitizedName = name
Expand All @@ -22,22 +22,27 @@ export class ArchiveManager {
}

public async downloadBackup(encrypted: boolean) {
const items = this.application.allItems();

const run = async () => {
// download in Standard Notes format
const intent = encrypted
? EncryptionIntent.FileEncrypted
: 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) {
const data = await this.itemsData(items, intent);
this.downloadData(
data!,
blobData,
`Standard Notes Encrypted Backup and Import File - ${this.formattedDate()}.txt`
);
} else {
/** download as zipped plain text files */
this.downloadZippedItems(items);
this.downloadZippedDecryptedItems(data);
}
};

Expand Down Expand Up @@ -65,15 +70,6 @@ export class ArchiveManager {
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() {
return (window as any).zip;
}
Expand All @@ -95,17 +91,19 @@ export class ArchiveManager {
});
}

private async downloadZippedItems(
items: SNItem[]
private async downloadZippedDecryptedItems(
data: BackupFile
) {
await this.loadZip();
const items = data.items;
this.zip.createWriter(
new this.zip.BlobWriter('application/zip'),
async (zipWriter: any) => {

const data = await this.application.createBackupFile(items, EncryptionIntent.FileDecrypted);
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(
'Standard Notes Backup and Import File.txt'
);
Expand Down
20 changes: 10 additions & 10 deletions app/assets/javascripts/services/desktopManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Bridge } from './bridge';
type UpdateObserverCallback = (component: SNComponent) => void
type ComponentActivationCallback = (payload: PurePayload) => void
type ComponentActivationObserver = {
id: string,
callback: ComponentActivationCallback
id: string;
callback: ComponentActivationCallback;
}

export class DesktopManager extends ApplicationService {
Expand All @@ -19,8 +19,9 @@ export class DesktopManager extends ApplicationService {
$timeout: ng.ITimeoutService
componentActivationObservers: ComponentActivationObserver[] = []
updateObservers: {
callback: UpdateObserverCallback
}[] = []
callback: UpdateObserverCallback;
}[] = [];

isDesktop = isDesktopApplication();

dataLoaded = false
Expand Down Expand Up @@ -187,12 +188,11 @@ export class DesktopManager extends ApplicationService {
});
}

desktop_requestBackupFile() {
return this.application!.createBackupFile(
undefined,
undefined,
true
);
async desktop_requestBackupFile() {
const data = this.application!.createBackupFile(EncryptionIntent.FileEncrypted);
if (data) {
return JSON.stringify(data, null, 2);
}
}

desktop_didBeginBackup() {
Expand Down

0 comments on commit e1f590f

Please sign in to comment.