-
Notifications
You must be signed in to change notification settings - Fork 262
/
Copy pathMyAssetsSource.js
93 lines (85 loc) · 2.65 KB
/
MyAssetsSource.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { BaseSource } from "./index";
import { ItemTypes } from "../../dnd";
import UploadSourcePanel from "../UploadSourcePanel";
import ModelNode from "../../../editor/nodes/ModelNode";
import VideoNode from "../../../editor/nodes/VideoNode";
import ImageNode from "../../../editor/nodes/ImageNode";
import AudioNode from "../../../editor/nodes/AudioNode";
import { AcceptsAllFileTypes } from "../fileTypes";
import { PRIVACY } from "../../../constants";
const assetTypeToNode = {
model: ModelNode,
image: ImageNode,
video: VideoNode,
audio: AudioNode
};
const assetTypeToItemType = {
model: ItemTypes.Model,
image: ItemTypes.Image,
video: ItemTypes.Video,
audio: ItemTypes.Audio
};
export default class MyAssetsSource extends BaseSource {
constructor(editor) {
super();
this.component = UploadSourcePanel;
this.editor = editor;
this.id = "assets";
this.name = "My Assets";
this.tags = [
{ label: "Models", value: "model" },
{ label: "Images", value: "image" },
{ label: "Videos", value: "video" },
{ label: "Audio", value: "audio" }
];
this.searchLegalCopy = "Search by Hubs";
this.privacyPolicyUrl = PRIVACY;
this.uploadSource = true;
this.uploadMultiple = true;
this.acceptFileTypes = AcceptsAllFileTypes;
this.requiresAuthentication = true;
}
async upload(files, onProgress, abortSignal) {
const assets = await this.editor.api.uploadAssets(this.editor, files, onProgress, abortSignal);
this.emit("resultsChanged");
return assets;
}
async delete(item) {
await this.editor.api.deleteAsset(item.id);
this.emit("resultsChanged");
}
async search(params, cursor, abortSignal) {
const { results, suggestions, nextCursor } = await this.editor.api.searchMedia(
this.id,
{
query: params.query,
type: params.tags && params.tags.length > 0 && params.tags[0].value
},
cursor,
abortSignal
);
return {
results: results.map(result => {
const thumbnailUrl = result && result.images && result.images.preview && result.images.preview.url;
const nodeClass = assetTypeToNode[result.type];
const iconComponent = thumbnailUrl ? null : this.editor.nodeEditors.get(nodeClass).iconComponent;
return {
id: result.id,
thumbnailUrl,
iconComponent,
label: result.name,
type: assetTypeToItemType[result.type],
url: result.url,
nodeClass,
initialProps: {
name: result.name,
src: result.url
}
};
}),
suggestions,
nextCursor,
hasMore: !!nextCursor
};
}
}