forked from aaronmars/martian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pageFileBase.js
67 lines (60 loc) · 2.42 KB
/
pageFileBase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { utility } from './lib/utility.js';
import { modelParser } from './lib/modelParser.js';
import { fileModel } from './models/file.model.js';
/**
* A base class for managing file attachments on both published pages and drafts. This class can not be instantiated directly.
*/
export class PageFileBase {
constructor(pageId, filename) {
if(this.constructor.name === 'PageFileBase') {
throw new TypeError('PageFileBase must not be constructed directly. Use one of PageFile() or DraftFile()');
}
this._pageId = utility.getResourceId(pageId, 'home');
this._filename = utility.getFilenameId(filename);
}
/**
* Get the URI for direct access to the file attachment.
* @returns {String} - The file URI.
*/
get fileUrl() {
return this._plug.url;
}
/**
* Gets the information for the file attachment.
* @returns {Promise.<fileModel>} - A Promise that, when resolved, yields a {@link fileModel} containing the file information.
*/
getInfo() {
let fileModelParser = modelParser.createParser(fileModel);
return this._plug.at('info').get().then((r) => r.json()).then(fileModelParser);
}
/**
* Delete the file attachment fron the page.
* @returns {Promise} - A Promise that, when resolved, indicates a successful delete operation.
*/
delete() {
return this._plug.delete();
}
/**
* Get the description of the file attachment.
* @returns {Promise.<String>} - A Promise that, when resolved, yields the file description.
*/
getDescription() {
return this._plug.at('description').get().then((r) => r.json());
}
/**
* Remove the description from the file attachment.
* @returns {Promise} - A Promise that, when resolved, indicates a successful removal.
*/
clearDescription() {
return this._plug.at('description').delete();
}
/**
* Update the description of the file attachment.
* @param {String} [description=''] - The new description to set.
* @returns {Promise.<fileModel>} - A Promise that, when resolved, yields a {@link fileModel} containing the file information.
*/
updateDescription(description = '') {
let fileModelParser = modelParser.createParser(fileModel);
return this._plug.at('description').put(description, utility.textRequestType).then((r) => r.json()).then(fileModelParser);
}
}