Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cocos/asset/asset-manager/editor-path-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
try {
let text = '';
if (EDITOR) {
const info: { library: { ['.bin']: any } } = await Editor.Message.request('asset-db', 'query-asset-info', uuid);
// eslint-disable-next-line max-len
const info: { library: { ['.bin']: any } } = await fetch(`/cocos-api/assets/queryAssetInfo/?uuid=${uuid}`).then((response) => response.json());
// Current rule: If an asset has only one .bin file, then it is in CCON format.
if (info && info.library['.bin'] && Object.keys(info.library).length === 1) {
text = '.cconb';
Expand All @@ -104,7 +105,7 @@
text = await fetchText(requestUrl) as string;
useAssetDB = false;
} catch (e) {
console.warn(`Failed to get file type from URL: ${requestUrl}. Error: ${e}`);

Check warning on line 108 in cocos/asset/asset-manager/editor-path-replace.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "unknown" of template literal expression
text = '';
}
}
Expand Down
8 changes: 6 additions & 2 deletions pal/wasm/wasm-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
try {
// NOTE: when it's in EDITOR, binaryUrl is a url with `external:` protocol.
if (EDITOR) {
Editor.Message.request('engine', 'query-engine-info').then((info) => {
fetch('/cocos-api/engine/queryEngineInfo').then((response) => response.json().then((info: any) => {
const externalRoot = `${info.native.path}/external/`;
binaryUrl = binaryUrl.replace('external:', externalRoot);
const arrayBuffer = native.fileUtils.getDataFromFile(binaryUrl);
resolve(arrayBuffer);
})).catch((e) => {
reject(e);
});
return;
}
Expand All @@ -56,10 +58,12 @@ export function fetchUrl (binaryUrl: string): Promise<string> {
try {
// NOTE: when it's in EDITOR, binaryUrl is a url with `external:` protocol.
if (EDITOR) {
Editor.Message.request('engine', 'query-engine-info').then((info) => {
fetch('/cocos-api/engine/queryEngineInfo').then((response) => response.json().then((info: any) => {
const externalRoot = `${info.native.path}/external/`;
binaryUrl = binaryUrl.replace('external:', externalRoot);
resolve(binaryUrl);
})).catch((e) => {
reject(e);
});
return;
}
Expand Down
26 changes: 3 additions & 23 deletions pal/wasm/wasm-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,9 @@ export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
return new Promise<ArrayBuffer>((resolve, reject) => {
try {
// NOTE: when it's in EDITOR or PREVIEW, binaryUrl is a url with `external:` protocol.
if (EDITOR) {
Editor.Message.request('engine', 'query-engine-info').then((info) => {
const externalRoot = `${info.native.path}/external/`;
binaryUrl = binaryUrl.replace('external:', externalRoot);
// IDEA: it's better we implement another PAL for nodejs platform.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
const arrayBuffer = fs.readFileSync(binaryUrl) as ArrayBuffer;
resolve(arrayBuffer);
});
return;
} else if (PREVIEW) {
if (EDITOR || PREVIEW) {
// NOTE: we resolve '/engine_external/' in editor preview server.
fetch(`/engine_external/?url=${binaryUrl}`).then((response) => response.arrayBuffer().then(resolve)).catch((e) => {
fetch(`/cocos-api/engine/queryEngineInfo/?url=${binaryUrl}`).then((response) => response.arrayBuffer().then(resolve)).catch((e) => {
// noop
});
return;
Expand All @@ -74,16 +63,7 @@ export function fetchUrl (binaryUrl: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
try {
// NOTE: when it's in EDITOR or PREVIEW, binaryUrl is a url with `external:` protocol.
if (EDITOR) {
Editor.Message.request('engine', 'query-engine-info').then((info) => {
const externalRoot = `${info.native.path}/external/`;
binaryUrl = binaryUrl.replace('external:', externalRoot);
// IDEA: it's better we implement another PAL for nodejs platform.
// eslint-disable-next-line @typescript-eslint/no-var-requires
resolve(binaryUrl);
});
return;
} else if (PREVIEW) {
if (EDITOR || PREVIEW) {
resolve(`/engine_external/?url=${binaryUrl}`);
return;
}
Expand Down
Loading