bitwarden-estensione-browser/libs/common/src/models/view/attachmentView.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.0 KiB
TypeScript
Raw Normal View History

import { Attachment } from "../domain/attachment";
2018-11-14 02:43:45 +01:00
import { SymmetricCryptoKey } from "../domain/symmetricCryptoKey";
2018-01-24 17:33:15 +01:00
2022-02-22 15:39:11 +01:00
import { View } from "./view";
2018-01-24 17:33:15 +01:00
export class AttachmentView implements View {
2019-01-25 15:30:21 +01:00
id: string = null;
url: string = null;
2019-04-14 03:20:04 +02:00
size: string = null;
2019-01-25 15:30:21 +01:00
sizeName: string = null;
fileName: string = null;
key: SymmetricCryptoKey = null;
2018-01-24 17:33:15 +01:00
2018-05-17 19:25:03 +02:00
constructor(a?: Attachment) {
if (!a) {
return;
2018-01-24 17:33:15 +01:00
}
2019-05-01 16:35:52 +02:00
2018-01-24 17:33:15 +01:00
this.id = a.id;
this.url = a.url;
this.size = a.size;
this.sizeName = a.sizeName;
2021-12-16 13:36:21 +01:00
}
2019-05-01 16:35:52 +02:00
get fileSize(): number {
try {
if (this.size != null) {
return parseInt(this.size, null);
}
} catch {
// Invalid file size.
2019-05-01 16:35:52 +02:00
}
return 0;
2021-12-16 13:36:21 +01:00
}
2022-06-24 02:38:55 +02:00
2022-06-29 06:00:05 +02:00
static fromJSON(obj: Partial<AttachmentView>): AttachmentView {
2022-06-29 02:23:01 +02:00
const view = new AttachmentView();
view.id = obj.id;
view.url = obj.url;
view.size = obj.size;
view.sizeName = obj.sizeName;
view.fileName = obj.fileName;
2022-06-24 02:38:55 +02:00
view.key = obj.key == null ? null : SymmetricCryptoKey.fromJSON(obj.key);
2022-06-29 02:23:01 +02:00
2022-06-24 02:38:55 +02:00
return view;
}
2018-01-24 17:33:15 +01:00
}