playcanvas / playcanvas/editor
getFileUrl returns inconsistent URL schema
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 215
- Avg merge
- 1d 29m
- Merged PRs (30d)
- 30
Description
asset.getFileUrl() returns inconsistent URL
This issue is noted at https://forum.playcanvas.com/t/x-frame-options-deny-on-assets/23837/3
Steps to Reproduce
- Create a new PlayCanvas project
- Add an asset such as index.html
- Launch the project
- In the JavaScript console type:
pc.app.asset.findAll('index.html', 'html')[0].getFileUrl();
Result
The response is a relative URL. i.e.
/api/assets/files/Library/MyProject/index.html?id=656796
Expected Response
We should get a FQURL (fully qualified/absolute URL) as we do when publishing. i.e.
https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/HSBSlcXy/..
Workaround
Currently we can sense when the API is accessed in launcher vs published; check the domain origin, look for the debug flag, or check for the protocol, and append the origin for relative assets i.e.
var url = pc.app.asset.findAll('index.html', 'html')[0].getFileUrl();
if (url.substring(0,4) != 'http') {
url = window.location.origin + url;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the asset.getFileUrl() entry point shown in the reproduction and inspect how it constructs URLs in the editor. Reproduce the console call with an asset such as index.html, then compare the result with the published URL behavior. Done means the method returns a fully qualified URL rather than the current relative path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100