1 | import { __decorate } from "tslib";
|
2 | import { headers } from "@pnp/queryable";
|
3 | import { defaultPath } from "../decorators.js";
|
4 | import { ReadableFile } from "../files/readable-file.js";
|
5 | import { spPost } from "../operations.js";
|
6 | import { _SPCollection, spInvokableFactory, deleteableWithETag, } from "../spqueryable.js";
|
7 | let _Attachments = class _Attachments extends _SPCollection {
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 | getByName(name) {
|
14 | const f = Attachment(this);
|
15 | f.concat(`('${name}')`);
|
16 | return f;
|
17 | }
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | async add(name, content) {
|
25 | const response = await spPost(Attachments(this, `add(FileName='${name}')`), { body: content });
|
26 | return {
|
27 | data: response,
|
28 | file: this.getByName(name),
|
29 | };
|
30 | }
|
31 | };
|
32 | _Attachments = __decorate([
|
33 | defaultPath("AttachmentFiles")
|
34 | ], _Attachments);
|
35 | export { _Attachments };
|
36 | export const Attachments = spInvokableFactory(_Attachments);
|
37 | export class _Attachment extends ReadableFile {
|
38 | constructor() {
|
39 | super(...arguments);
|
40 | this.delete = deleteableWithETag();
|
41 | }
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 | async setContent(body) {
|
48 | await spPost(Attachment(this, "$value"), headers({ "X-HTTP-Method": "PUT" }, { body }));
|
49 | return this;
|
50 | }
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | recycle(eTag = "*") {
|
57 | return spPost(Attachment(this, "recycleObject"), headers({
|
58 | "IF-Match": eTag,
|
59 | "X-HTTP-Method": "DELETE",
|
60 | }));
|
61 | }
|
62 | }
|
63 | export const Attachment = spInvokableFactory(_Attachment);
|
64 |
|
\ | No newline at end of file |