/
setItemThumbnail.ts
49 lines (48 loc) · 1.05 KB
/
setItemThumbnail.ts
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
import { IUserRequestOptions } from "@esri/arcgis-rest-auth";
import { updateItem } from "@esri/arcgis-rest-portal";
import HubError from "../HubError";
/**
* Upload a file to be used as the thumbnail for an item
* @param id
* @param file
* @param filename
* @param requestOptions
*/
export async function setItemThumbnail(
id: string,
file: any,
filename: string,
requestOptions: IUserRequestOptions,
owner: string
): Promise<void> {
const opts = {
item: {
id,
},
owner,
params: {
thumbnail: file,
fileName: filename,
},
filename,
...requestOptions,
};
try {
const response = await updateItem(opts);
if (!response.success) {
throw new HubError(
"Set Project Thumbnail",
"Unknown error setting thumbnail."
);
}
} catch (err) {
if (err instanceof Error) {
throw new HubError("Set Project Thumbnail", err.message, err);
} else {
throw new HubError(
"Set Project Thumbnail",
"Unknown error setting thumbnail."
);
}
}
}