1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
12 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
13 | };
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 | const path_1 = __importDefault(require("path"));
|
16 | const client_1 = require("./client");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | class File {
|
22 | constructor(client, name, baseName, lastmod, size, mime, id) {
|
23 | this.memento = {
|
24 | baseName,
|
25 | deleted: false,
|
26 | id,
|
27 | lastmod: new Date(lastmod),
|
28 | mime,
|
29 | name,
|
30 | size,
|
31 | };
|
32 | this.client = client;
|
33 | }
|
34 | |
35 |
|
36 |
|
37 |
|
38 | get name() {
|
39 | this.assertExistence();
|
40 | return this.memento.name;
|
41 | }
|
42 | |
43 |
|
44 |
|
45 |
|
46 | get baseName() {
|
47 | this.assertExistence();
|
48 | return this.memento.baseName;
|
49 | }
|
50 | |
51 |
|
52 |
|
53 |
|
54 | get lastmod() {
|
55 | this.assertExistence();
|
56 | return this.memento.lastmod;
|
57 | }
|
58 | |
59 |
|
60 |
|
61 |
|
62 | get size() {
|
63 | this.assertExistence();
|
64 | return this.memento.size;
|
65 | }
|
66 | |
67 |
|
68 |
|
69 | get mime() {
|
70 | this.assertExistence();
|
71 | return this.memento.mime;
|
72 | }
|
73 | |
74 |
|
75 |
|
76 | get id() {
|
77 | this.assertExistence();
|
78 | return this.memento.id;
|
79 | }
|
80 | |
81 |
|
82 |
|
83 |
|
84 | delete() {
|
85 | return __awaiter(this, void 0, void 0, function* () {
|
86 | this.memento.deleted = true;
|
87 | return yield this.client.deleteFile(this.memento.name);
|
88 | });
|
89 | }
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 | getFolder() {
|
96 | return __awaiter(this, void 0, void 0, function* () {
|
97 | this.assertExistence();
|
98 | const folder = yield this.client.getFolder(path_1.default.dirname((this.memento.name)));
|
99 | if (folder) {
|
100 | return folder;
|
101 | }
|
102 | throw new client_1.ClientError("Error, the folder of the file does not exist anymore", "ERR_FILE_FOLDER_DOES_NOT_EXIST");
|
103 | });
|
104 | }
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | move(targetFileName) {
|
112 | return __awaiter(this, void 0, void 0, function* () {
|
113 | this.assertExistence();
|
114 | const file = yield this.client.moveFile(this.name, targetFileName);
|
115 | this.memento.name = file.name;
|
116 | this.memento.baseName = file.baseName;
|
117 | this.memento.lastmod = file.lastmod;
|
118 | this.memento.mime = file.mime;
|
119 | this.memento.size = file.size;
|
120 | return this;
|
121 | });
|
122 | }
|
123 | |
124 |
|
125 |
|
126 |
|
127 | getContent() {
|
128 | return __awaiter(this, void 0, void 0, function* () {
|
129 | this.assertExistence();
|
130 | return this.client.getContent(this.name);
|
131 | });
|
132 | }
|
133 | |
134 |
|
135 |
|
136 |
|
137 | getUrl() {
|
138 | this.assertExistence();
|
139 | return this.client.getLink(this.name);
|
140 | }
|
141 | |
142 |
|
143 |
|
144 |
|
145 | getUIUrl() {
|
146 | this.assertExistence();
|
147 | return this.client.getUILink(this.id);
|
148 | }
|
149 | |
150 |
|
151 |
|
152 |
|
153 | addTag(tagName) {
|
154 | return __awaiter(this, void 0, void 0, function* () {
|
155 | this.assertExistence();
|
156 | return this.client.addTagToFile(this.id, tagName);
|
157 | });
|
158 | }
|
159 | |
160 |
|
161 |
|
162 |
|
163 | getTags() {
|
164 | return __awaiter(this, void 0, void 0, function* () {
|
165 | this.assertExistence();
|
166 | const map = yield this.client.getTagsOfFile(this.id);
|
167 | const tagNames = [];
|
168 | for (const tagName of map) {
|
169 | tagNames.push(tagName[0]);
|
170 | }
|
171 | return tagNames;
|
172 | });
|
173 | }
|
174 | |
175 |
|
176 |
|
177 |
|
178 | removeTag(tagName) {
|
179 | return __awaiter(this, void 0, void 0, function* () {
|
180 | this.assertExistence();
|
181 | const map = yield this.client.getTagsOfFile(this.id);
|
182 | const tagId = map.get(tagName);
|
183 | if (tagId) {
|
184 | yield this.client.removeTagOfFile(this.id, tagId);
|
185 | }
|
186 | });
|
187 | }
|
188 | |
189 |
|
190 |
|
191 |
|
192 | addComment(comment) {
|
193 | return __awaiter(this, void 0, void 0, function* () {
|
194 | this.assertExistence();
|
195 | return yield this.client.addCommentToFile(this.id, comment);
|
196 | });
|
197 | }
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | getComments(top, skip) {
|
206 | return __awaiter(this, void 0, void 0, function* () {
|
207 | this.assertExistence();
|
208 | return yield this.client.getFileComments(this.id, top, skip);
|
209 | });
|
210 | }
|
211 | assertExistence() {
|
212 | if (this.memento.deleted) {
|
213 | throw new client_1.ClientError("File does not exist", "ERR_FILE_NOT_EXISTING");
|
214 | }
|
215 | }
|
216 | }
|
217 | exports.default = File;
|