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 |
|
16 | const debug = require("debug").debug("Folder");
|
17 | const error_1 = __importDefault(require("./error"));
|
18 | class Folder {
|
19 | constructor(client, name, baseName, lastmod, id = -1) {
|
20 | this.client = client;
|
21 | this.memento = {
|
22 | baseName,
|
23 | deleted: false,
|
24 | id,
|
25 | lastmod: new Date(lastmod),
|
26 | name,
|
27 | };
|
28 | }
|
29 | get name() {
|
30 | this.assertExistence();
|
31 | return this.memento.name;
|
32 | }
|
33 | get baseName() {
|
34 | this.assertExistence();
|
35 | return this.memento.baseName;
|
36 | }
|
37 | get lastmod() {
|
38 | this.assertExistence();
|
39 | return this.memento.lastmod;
|
40 | }
|
41 | get id() {
|
42 | this.assertExistence();
|
43 | return this.memento.id;
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 | getSubFolders() {
|
50 | return __awaiter(this, void 0, void 0, function* () {
|
51 | this.assertExistence();
|
52 | return yield this.client.getSubFolders(this.name);
|
53 | });
|
54 | }
|
55 | |
56 |
|
57 |
|
58 |
|
59 | hasSubFolder(subFolderBaseName) {
|
60 | return __awaiter(this, void 0, void 0, function* () {
|
61 | this.assertExistence();
|
62 | const subFolder = yield this.client.getFolder(this.name + "/" + subFolderBaseName);
|
63 | if (subFolder) {
|
64 | return true;
|
65 | }
|
66 | return false;
|
67 | });
|
68 | }
|
69 | |
70 |
|
71 |
|
72 | getFiles() {
|
73 | return __awaiter(this, void 0, void 0, function* () {
|
74 | this.assertExistence();
|
75 | return yield this.client.getFiles(this.name);
|
76 | });
|
77 | }
|
78 | |
79 |
|
80 |
|
81 |
|
82 | createSubFolder(subFolderBaseName) {
|
83 | return __awaiter(this, void 0, void 0, function* () {
|
84 | this.assertExistence();
|
85 | return yield this.client.createFolder(this.name + "/" + subFolderBaseName);
|
86 | });
|
87 | }
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | getFile(fileBaseName) {
|
95 | return __awaiter(this, void 0, void 0, function* () {
|
96 | this.assertExistence();
|
97 | return this.client.getFile(this.name + "/" + fileBaseName);
|
98 | });
|
99 | }
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | createFile(fileBaseName, data) {
|
108 | return __awaiter(this, void 0, void 0, function* () {
|
109 | this.assertExistence();
|
110 |
|
111 | debug("createFile fileBaseName = %s", fileBaseName);
|
112 | const invalidChars = [":", "*", "/", "\\", "\"", "?", "<", ">"];
|
113 |
|
114 | for (const invalidChar of invalidChars) {
|
115 | if (fileBaseName.indexOf(invalidChar) !== -1) {
|
116 | throw new error_1.default("Filename contains an invalid character '" + invalidChar + "'", "ERR_INVALID_CHAR_IN_FILE_NAME", { fileBaseName });
|
117 | }
|
118 | }
|
119 | return this.client.createFile(this.name + "/" + fileBaseName.replace(/^\/+/g, ""), data);
|
120 | });
|
121 | }
|
122 | |
123 |
|
124 |
|
125 |
|
126 | delete() {
|
127 | return __awaiter(this, void 0, void 0, function* () {
|
128 | debug("delete");
|
129 | this.memento.deleted = true;
|
130 | return yield this.client.deleteFolder(this.memento.name);
|
131 | });
|
132 | }
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | move(targetFolderName) {
|
140 | return __awaiter(this, void 0, void 0, function* () {
|
141 | this.assertExistence();
|
142 | const folder = yield this.client.moveFolder(this.name, targetFolderName);
|
143 | this.memento.name = folder.name;
|
144 | this.memento.baseName = folder.baseName;
|
145 | this.memento.lastmod = folder.lastmod;
|
146 | return this;
|
147 | });
|
148 | }
|
149 | |
150 |
|
151 |
|
152 |
|
153 | getUrl() {
|
154 | this.assertExistence();
|
155 | return this.client.getLink(this.name);
|
156 | }
|
157 | |
158 |
|
159 |
|
160 |
|
161 | getUIUrl() {
|
162 | this.assertExistence();
|
163 | return this.client.getUILink(this.id);
|
164 | }
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 | containsFile(fileBaseName) {
|
171 | return __awaiter(this, void 0, void 0, function* () {
|
172 | this.assertExistence();
|
173 | let file;
|
174 | file = yield this.getFile(fileBaseName);
|
175 | if (file) {
|
176 | return true;
|
177 | }
|
178 | return false;
|
179 | });
|
180 | }
|
181 | |
182 |
|
183 |
|
184 |
|
185 | addTag(tagName) {
|
186 | return __awaiter(this, void 0, void 0, function* () {
|
187 | return yield this.client.addTagToFile(this.id, tagName);
|
188 | });
|
189 | }
|
190 | |
191 |
|
192 |
|
193 |
|
194 | getTags() {
|
195 | return __awaiter(this, void 0, void 0, function* () {
|
196 | this.assertExistence();
|
197 | const map = yield this.client.getTagsOfFile(this.id);
|
198 | const tagNames = [];
|
199 | for (const tagName of map) {
|
200 | tagNames.push(tagName[0]);
|
201 | }
|
202 | return tagNames;
|
203 | });
|
204 | }
|
205 | |
206 |
|
207 |
|
208 |
|
209 | removeTag(tagName) {
|
210 | return __awaiter(this, void 0, void 0, function* () {
|
211 | this.assertExistence();
|
212 | const map = yield this.client.getTagsOfFile(this.id);
|
213 | const tagNames = [];
|
214 | const tagId = map.get(tagName);
|
215 | if (tagId) {
|
216 | yield this.client.removeTagOfFile(this.id, tagId);
|
217 | }
|
218 | });
|
219 | }
|
220 | |
221 |
|
222 |
|
223 |
|
224 | addComment(comment) {
|
225 | return __awaiter(this, void 0, void 0, function* () {
|
226 | this.assertExistence();
|
227 | return yield this.client.addCommentToFile(this.id, comment);
|
228 | });
|
229 | }
|
230 | |
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | getComments(top, skip) {
|
238 | return __awaiter(this, void 0, void 0, function* () {
|
239 | this.assertExistence();
|
240 | return yield this.client.getFileComments(this.id, top, skip);
|
241 | });
|
242 | }
|
243 | assertExistence() {
|
244 | if (this.memento.deleted) {
|
245 | throw new error_1.default("Folder does not exist", "ERR_FOLDER_NOT_EXISTING");
|
246 | }
|
247 | }
|
248 | }
|
249 | exports.default = Folder;
|