Skip to content

Commit 9bfccb4

Browse files
committed
fetch from assets from cdn
1 parent 259f982 commit 9bfccb4

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

src/lib/project-fetcher-hoc.jsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ const ProjectFetcherHOC = function (WrappedComponent) {
111111
}
112112
}
113113
fetchProject(projectId, loadingState) {
114-
// pm: this is because im a lazy bum and i need to be able to access the project id
115-
// if you hate it, then damn. fix it. im the backend dev. i aint dealing with this.
116-
window.__currentProjectID = projectId;
117-
118114
// tw: clear and stop the VM before fetching
119115
// these will also happen later after the project is fetched, but fetching may take a while and
120116
// the project shouldn't be running while fetching the new project
@@ -176,7 +172,8 @@ const ProjectFetcherHOC = function (WrappedComponent) {
176172
storage.DataFormat.JSON,
177173
);
178174
} else {
179-
projectUrl = `https://projects.penguinmod.com/api/v1/projects/getprojectwrapper?safe=true&projectId=${projectId}`;
175+
storage.setProjectID(projectId);
176+
projectUrl = `https://projects.penguinmod.com/api/v1/projects/getprojectwrapper?safe=true&projectId=${projectId}&assets=false`;
180177
assetPromise = progressMonitor
181178
.fetchWithProgress(projectUrl)
182179
.then(async (r) => {
@@ -202,20 +199,15 @@ const ProjectFetcherHOC = function (WrappedComponent) {
202199
let zip = new JSZip();
203200
zip.file("project.json", JSON.stringify(json));
204201

205-
if (typeof project.assets !== "object") {
206-
alert(
207-
"No assets were returned. This error is temporary and should not be reported.",
208-
);
209-
throw new TypeError(
210-
"Invalid type given inside the assets list",
211-
);
212-
}
202+
/*
203+
// we will fetch assets later now
213204
for (const asset of project.assets) {
214205
zip.file(
215206
asset.id,
216207
new Uint8Array(asset.buffer.data).buffer,
217208
);
218209
}
210+
*/
219211

220212
const arrayBuffer = await zip.generateAsync({
221213
type: "arraybuffer",
@@ -367,7 +359,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
367359
};
368360
ProjectFetcherComponent.defaultProps = {
369361
assetHost:
370-
"https://projects.penguinmod.com/api/v1/projects/backupassetget",
362+
"https://asset-cdn.penguinmod.com/file/penguinmod-warm-tier-s2-cf",
371363
projectHost: "https://projects.scratch.mit.edu",
372364
};
373365

src/lib/storage.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Storage extends ScratchStorage {
3939
setProjectToken(projectToken) {
4040
this.projectToken = projectToken;
4141
}
42+
setProjectID(projectId) {
43+
this.projectId = projectId;
44+
}
4245
getProjectGetConfig(projectAsset) {
4346
const path = `${this.projectHost}/${projectAsset.assetId}`;
4447
const qs = this.projectToken ? `?token=${this.projectToken}` : "";
@@ -61,11 +64,11 @@ class Storage extends ScratchStorage {
6164
this.assetHost = assetHost;
6265
}
6366
getAssetGetConfig(asset) {
64-
if (window.__currentProjectID == "0") {
67+
if (!this.projectId) {
6568
return `https://assets.scratch.mit.edu/internalapi/asset/${asset.assetId}.${asset.dataFormat}/get/`;
6669
}
6770

68-
return `${this.assetHost}?asset_name=${window.__currentProjectID}_${asset.assetId}.${asset.dataFormat}`;
71+
return `${this.assetHost}/${this.projectId}_${asset.assetId}.${asset.dataFormat}`;
6972
}
7073
getAssetCreateConfig(asset) {
7174
return {

0 commit comments

Comments
 (0)