1 | import { __decorate } from "tslib";
|
2 | import { headers, BlobParse, TextParse, JSONParse, BufferParse } from "@pnp/queryable";
|
3 | import { defaultPath } from "../decorators.js";
|
4 | import { spPost } from "../operations.js";
|
5 | import { _SPCollection, spInvokableFactory, _SPInstance, deleteableWithETag, } from "../spqueryable.js";
|
6 | let _Attachments = class _Attachments extends _SPCollection {
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 | getByName(name) {
|
13 | const f = Attachment(this);
|
14 | f.concat(`('${name}')`);
|
15 | return f;
|
16 | }
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | async add(name, content) {
|
24 | const response = await spPost(Attachments(this, `add(FileName='${name}')`), { body: content });
|
25 | return {
|
26 | data: response,
|
27 | file: this.getByName(name),
|
28 | };
|
29 | }
|
30 | };
|
31 | _Attachments = __decorate([
|
32 | defaultPath("AttachmentFiles")
|
33 | ], _Attachments);
|
34 | export { _Attachments };
|
35 | export const Attachments = spInvokableFactory(_Attachments);
|
36 | export class _Attachment extends _SPInstance {
|
37 | constructor() {
|
38 | super(...arguments);
|
39 | this.delete = deleteableWithETag();
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 | getText() {
|
46 | return this.getParsed(TextParse());
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 | getBlob() {
|
53 | return this.getParsed(BlobParse());
|
54 | }
|
55 | |
56 |
|
57 |
|
58 | getBuffer() {
|
59 | return this.getParsed(BufferParse());
|
60 | }
|
61 | |
62 |
|
63 |
|
64 | getJSON() {
|
65 | return this.getParsed(JSONParse());
|
66 | }
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 | async setContent(content) {
|
73 | await spPost(Attachment(this, "$value"), headers({ "X-HTTP-Method": "PUT" }, {
|
74 | body: content,
|
75 | }));
|
76 | return this;
|
77 | }
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 | recycle(eTag = "*") {
|
84 | return spPost(Attachment(this, "recycleObject"), headers({
|
85 | "IF-Match": eTag,
|
86 | "X-HTTP-Method": "DELETE",
|
87 | }));
|
88 | }
|
89 | getParsed(parser) {
|
90 | return Attachment(this, "$value").using(parser)();
|
91 | }
|
92 | }
|
93 | export const Attachment = spInvokableFactory(_Attachment);
|
94 |
|
\ | No newline at end of file |