2024-10-21 11:29:17 +08:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
2018-10-13 17:07:54 +08:00
|
|
|
import { Utils } from '../utils/utils';
|
2018-11-22 11:26:00 +08:00
|
|
|
import FileTag from './file-tag';
|
2018-10-13 17:07:54 +08:00
|
|
|
|
2024-10-21 11:29:17 +08:00
|
|
|
dayjs.extend(relativeTime);
|
|
|
|
|
2018-10-13 17:07:54 +08:00
|
|
|
class Dirent {
|
|
|
|
constructor(json) {
|
2019-01-23 16:25:14 +08:00
|
|
|
this.id = json.id || '0000000000000000';
|
2018-10-13 17:07:54 +08:00
|
|
|
this.name = json.name;
|
|
|
|
this.type = json.type;
|
2019-01-04 13:53:30 +08:00
|
|
|
this.mtime = json.mtime;
|
2024-10-21 11:29:17 +08:00
|
|
|
if (!json.mtime) {
|
2019-09-09 11:34:12 +08:00
|
|
|
this.mtime_relative = '';
|
|
|
|
} else {
|
2024-10-21 11:29:17 +08:00
|
|
|
this.mtime_relative = dayjs.unix(json.mtime).fromNow();
|
2019-09-09 11:34:12 +08:00
|
|
|
}
|
2019-01-23 16:25:14 +08:00
|
|
|
this.permission = json.permission || 'rw';
|
2025-04-18 17:06:15 +08:00
|
|
|
this.isSelected = json.isSelected || false; // is check or not
|
2019-02-18 20:26:55 +08:00
|
|
|
this.starred = json.starred || false;
|
2023-11-15 17:01:50 +08:00
|
|
|
if (json.type === 'dir') {
|
|
|
|
this.has_been_shared_out = false;
|
|
|
|
}
|
2018-10-13 17:07:54 +08:00
|
|
|
if (json.type === 'file') {
|
2024-09-20 14:29:37 +08:00
|
|
|
this.size_original = json.size_original || json.size;
|
|
|
|
this.size = (typeof json.size === 'number') ? Utils.bytesToSize(json.size) : json.size;
|
2019-01-05 11:43:33 +08:00
|
|
|
this.is_locked = json.is_locked || false;
|
2023-11-21 13:53:40 +08:00
|
|
|
this.is_freezed = json.is_freezed || false;
|
2019-01-23 16:25:14 +08:00
|
|
|
this.lock_time = json.lock_time || '';
|
2024-07-18 11:58:42 +08:00
|
|
|
this.lock_owner = json.lock_owner || null;
|
|
|
|
this.lock_owner_name = json.lock_owner_name || null;
|
2019-01-23 16:25:14 +08:00
|
|
|
this.locked_by_me = json.locked_by_me || false;
|
|
|
|
this.modifier_name = json.modifier_name || '';
|
|
|
|
this.modifier_email = json.modifier_email || '';
|
|
|
|
this.modifier_contact_email = json.modifier_contact_email || '';
|
2018-11-22 11:26:00 +08:00
|
|
|
let file_tags = [];
|
|
|
|
if (json.file_tags) {
|
|
|
|
file_tags = json.file_tags.map(item => {
|
|
|
|
return new FileTag(item);
|
2018-11-28 08:57:42 +08:00
|
|
|
});
|
2018-11-22 11:26:00 +08:00
|
|
|
}
|
|
|
|
this.file_tags = file_tags;
|
2019-01-11 16:16:07 +08:00
|
|
|
if (json.encoded_thumbnail_src) {
|
|
|
|
this.encoded_thumbnail_src = json.encoded_thumbnail_src;
|
|
|
|
}
|
2023-06-20 21:18:07 +08:00
|
|
|
if (Utils.isSdocFile(json.name)) {
|
2023-07-24 10:47:12 +08:00
|
|
|
this.is_sdoc_revision = json.is_sdoc_revision || false;
|
|
|
|
this.revision_id = json.revision_id || null;
|
2023-06-20 21:18:07 +08:00
|
|
|
}
|
2018-10-13 17:07:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:44:04 +08:00
|
|
|
clone() {
|
|
|
|
return new Dirent(this);
|
|
|
|
}
|
|
|
|
|
2018-11-22 11:26:00 +08:00
|
|
|
isDir() {
|
|
|
|
return this.type !== 'file';
|
|
|
|
}
|
|
|
|
|
2024-12-21 18:22:08 +08:00
|
|
|
toJson() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
name: this.name,
|
|
|
|
mtime: this.mtime,
|
|
|
|
type: this.type,
|
2025-05-29 16:20:20 +08:00
|
|
|
is_dir: this.type !== 'file',
|
2024-12-21 18:22:08 +08:00
|
|
|
size: this.size,
|
|
|
|
modifier_name: this.modifier_name,
|
|
|
|
modifier_email: this.modifier_email,
|
|
|
|
modifier_contact_email: this.modifier_contact_email,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-13 17:07:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Dirent;
|