-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
234 lines (213 loc) · 7.5 KB
/
seed.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
const db = require("./server/db/db");
const { User, Asset } = require("./server/db/models");
const axios = require("axios");
const users = [
{
name: "john",
email: "[email protected]",
password: "123"
},
{
name: "frank",
email: "[email protected]",
password: "456"
},
{
name: "josh",
email: "[email protected]",
password: "abc"
},
{
name: "ryan",
email: "[email protected]",
password: "123456"
}
];
const ownership = [];
const isGLTF = asset =>
asset.formats.filter(format => format.formatType === "GLTF2").length > 0;
const assetUrlFilter = asset =>
asset.formats.filter(asset => asset.formatType === "GLTF2")[0].root.url;
let validAssets = [];
const seed = async () => {
try {
const resAnimals = await axios.get(
"https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=ANIMALS"
);
const resArchitecture = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=ARCHITECTURE")
const resArt = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=ART")
const resFood = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=FOOD")
const resNature = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=NATURE")
const resObjects = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=OBJECTS")
const resPeople = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=PEOPLE")
const resScenes = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=SCENES")
const resTechnology = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=TECH")
const resTransport = await axios.get("https://poly.googleapis.com/v1/assets?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4&pageSize=5&maxComplexity=SIMPLE&category=TRANSPORT")
const resDropLogo = await axios.get('https://poly.googleapis.com/v1/assets/dp5PrzF0k6W?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4')
const resFullstackLogo = await axios.get('https://poly.googleapis.com/v1/assets/0bJ0ctZdJV_?key=AIzaSyDbAkOgCpfiweD3ZQ3_ZyR0UBEqD17ZBs4')
const animals = resAnimals.data.assets;
const architecture = resArchitecture.data.assets;
const art = resArt.data.assets
const food = resFood.data.assets
const nature = resNature.data.assets
const objects = resObjects.data.assets
const people = resPeople.data.assets
const scenes = resScenes.data.assets
const technology = resTechnology.data.assets
const transport = resTransport.data.assets
const logos = [resDropLogo.data, resFullstackLogo.data]
logos.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "N/A"
});
}
});
animals.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Animals"
});
}
});
architecture.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Architecture",
});
}
});
art.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Art",
});
}
});
food.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Food",
});
}
});
nature.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Nature",
});
}
});
objects.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Objects",
});
}
});
people.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "People",
});
}
});
scenes.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Scenes",
});
}
});
technology.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Technology",
});
}
});
transport.forEach(asset => {
if (isGLTF(asset)) {
validAssets.push({
displayName: asset.displayName,
authorName: asset.authorName,
thumbnailUrl: asset.thumbnail.url,
googleApiId: asset.name,
assetUrl: assetUrlFilter(asset),
category: "Transport",
});
}
});
await Promise.all(users.map(user => User.create(user)));
await Promise.all(validAssets.map(asset => Asset.create(asset)));
const seedTestUser = await User.findById(4)
await seedTestUser.setAssets([1,2])
} catch (error) {
console.error(error);
}
};
const main = async () => {
try {
console.log("syncing db..");
db.sync({ force: true });
await seed();
} catch (error) {
console.log("error while seeding");
console.log(error.stack);
} finally {
console.log('The seed is sown.')
db.close();
}
};
main();
module.exports = main;