altmp / altv-issues

Issues and roadmap for alt:V project
92 stars 17 forks source link

Support full link in CDN's connect.json #2285

Closed hunteriii closed 1 month ago

hunteriii commented 1 month ago

Description of the problem

After packing the resources with altv.exe --host 127.0.0.1 --port 7788 --justpack, we need to add an extra link property to connect.json in order to download the resource from file sharing services like Dropbox.

Take a look at Additional context.

"link": "https://www.dropbox.com/scl/fi/123/webview.resource?dl=1"

Desired solution for the problem

For example, wget package are able to follow redirects. Follow redirects is very important.

Lets imagine we specify https://db.com/webview.resource in link property. If db.com redirect us to other domain (db_asset.com), we have to follow that.

If link propery doesn't exist, download the resource from "host": "127.0.0.1". If link property exist, download the resource from the specified link.

Alternatives you considered

No response

Additional context

{
    "disable-optional-props": false,
    "files": [
        {
            "hash": "8ac348f2e81b5a7",
            "name": "main",
            "size": 103705,
            "type": "js",
            "link": "https://www.dropbox.com/scl/fi/123/webview.resource?dl=1"
        }
    ],
    "hash-client-resource-names": false,
    "host": "127.0.0.1",
    "mtu": 1392,
    "optional-permissions": [],
    "port": 7788,
    "required-permissions": [],
    "shared-project-key": "",
    "shared-project-name": "",
    "spawn-after-connect": false
}
Iamproplayer7 commented 1 month ago

You can make your own proxy for that, just create a cdn and make those redirects yourself. Lets take localhost:5555 as cdn, when localhost:5555/connect.json is called send connec you have. When localhost:5555/webview.resource is called redirect to page that have file ready to download. And here we go there is your enchantment.

hunteriii commented 1 month ago

@Iamproplayer7 Thank you, but I test this already on Nginx.

The below config works on browser, but doesn't work on alt:V.

# server.toml

useCdn = true
cdnUrl = '127.0.0.1:81'
# nginx.conf

server {
    listen 81;

    location / {
        root html;
        index index.html;
    }

    location /webview.resource {
        return 301 "https://www.dropbox.com/scl/fi/123/webview.resource?dl=1";
    }
}

54888568954

Iamproplayer7 commented 1 month ago

@hunteriii It seems you need include ?rlkey=** in the link.

My example how i made it work:

const express = require('express');
const app = express()
app.listen(3333);

app.get('/', (req, res) => {
    return res.send('works');
});

app.get('/connect.json', (req, res) => {
    console.log('Fetch connect.json?')
    return res.json({ 
        "files":[
            {"hash":"884087420585f320","name":"testresource","size":146,"type":"js"},
        ],
        "host":"127.0.0.1",
        "mtu":1392,
        "port":7788
    });
});

app.get('/testresource.resource', (req, res) => {
    console.log('Download file?');
    return res.redirect('https://www.dropbox.com/scl/fi/5grzjbltysdmsaojbr1l3/testresource.resource?rlkey=9s3gb4pjbzctbaejd9pwfbzor&dl=1')
})

And thats works and it should work with nginx redirect too. (removing ?rlkey from the url does not work anymore)

Image from test with clean cache when resource forced to download: image image image

hunteriii commented 1 month ago

I had a problem with Windows Firewall. https://github.com/altmp/altv-issues/issues/2285#issuecomment-2139675147 works perfectly. Thank you.