2021-02-17 21:40:21 +08:00
|
|
|
import { FileInfo } from 'Common/File';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractModel } from 'Knoin/AbstractModel';
|
2022-10-31 05:19:52 +08:00
|
|
|
import { addObservablesTo, addComputablesTo } from 'External/ko';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class ComposeAttachmentModel extends AbstractModel {
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @param {string} id
|
|
|
|
* @param {string} fileName
|
|
|
|
* @param {?number=} size = null
|
|
|
|
* @param {boolean=} isInline = false
|
|
|
|
* @param {boolean=} isLinked = false
|
2023-01-25 01:58:25 +08:00
|
|
|
* @param {string=} cId = ''
|
2016-07-07 05:03:30 +08:00
|
|
|
* @param {string=} contentLocation = ''
|
|
|
|
*/
|
2023-01-25 01:58:25 +08:00
|
|
|
constructor(id, fileName, size = null, isInline = false, isLinked = false, cId = '', contentLocation = '') {
|
2020-10-19 01:19:45 +08:00
|
|
|
super();
|
2016-07-07 05:03:30 +08:00
|
|
|
|
|
|
|
this.id = id;
|
|
|
|
this.isInline = !!isInline;
|
|
|
|
this.isLinked = !!isLinked;
|
2023-01-25 01:58:25 +08:00
|
|
|
this.cId = cId;
|
2016-07-07 05:03:30 +08:00
|
|
|
this.contentLocation = contentLocation;
|
|
|
|
this.fromMessage = false;
|
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addObservablesTo(this, {
|
2020-10-25 18:46:58 +08:00
|
|
|
fileName: fileName,
|
|
|
|
size: size,
|
|
|
|
tempName: '',
|
2022-11-16 22:14:00 +08:00
|
|
|
type: '', // application/octet-stream
|
2020-10-25 18:46:58 +08:00
|
|
|
|
|
|
|
progress: 0,
|
|
|
|
error: '',
|
|
|
|
waiting: true,
|
|
|
|
uploading: false,
|
|
|
|
enabled: true,
|
|
|
|
complete: false
|
|
|
|
});
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addComputablesTo(this, {
|
2020-10-25 21:14:14 +08:00
|
|
|
progressText: () => {
|
|
|
|
const p = this.progress();
|
2022-10-10 19:52:56 +08:00
|
|
|
return 1 > p ? '' : (100 < p ? 100 : p) + '%';
|
2020-10-25 21:14:14 +08:00
|
|
|
},
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2020-10-25 21:14:14 +08:00
|
|
|
progressStyle: () => {
|
|
|
|
const p = this.progress();
|
2022-10-10 19:52:56 +08:00
|
|
|
return 1 > p ? '' : 'width:' + (100 < p ? 100 : p) + '%';
|
2020-10-25 21:14:14 +08:00
|
|
|
},
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2020-10-25 21:14:14 +08:00
|
|
|
title: () => this.error() || this.fileName(),
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2020-10-25 21:14:14 +08:00
|
|
|
friendlySize: () => {
|
|
|
|
const localSize = this.size();
|
2021-02-17 21:40:21 +08:00
|
|
|
return null === localSize ? '' : FileInfo.friendlySize(localSize);
|
2020-10-25 21:14:14 +08:00
|
|
|
},
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-11-16 22:14:00 +08:00
|
|
|
mimeType: () => this.type() || FileInfo.getContentType(this.fileName()),
|
2022-10-10 19:52:56 +08:00
|
|
|
fileExt: () => FileInfo.getExtension(this.fileName()),
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-10-10 19:52:56 +08:00
|
|
|
iconClass: () => FileInfo.getIconClass(this.fileExt(), this.mimeType())
|
|
|
|
});
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
}
|