I've deleted scripts

To download an archive of the project as is. This uses Python3 with a bunch of libraries like requests that you may need to install. This is very specific to my folder structure so you will need to change a few lines/folder paths.

import sys
import requests
import time
import subprocess
import os
import shutil
import zipfile
import io
import re

FNULL = open(os.devnull, 'w')

snapshot_path = '../snapshots-project'
project_id = '475452'
export_url = 'https://playcanvas.com/api/projects/{}/export'.format(project_id)
job_url_template = 'https://playcanvas.com/api/jobs/{}'

headers = {
    'Authorization':'Bearer fkldjsflfjfjklejflsefjeklsf',
    'Content-Type':'application/json'
}

job_poll_interval_secs = 1

job_id = -1
archive_url = ''

# Request the archive of the project
print('Requesting project archive job')
r = requests.post(export_url, headers=headers)
if r.status_code == 200:
    json = r.json()
    status = json['status']

    if status == 'running':
        job_id = json['id']
    elif status == 'complete':
        archive_url = json['url']
    else:
        sys.exit(1)
else:
    print('Error: {}'.format(r.status_code))
    sys.exit(1)

if len(archive_url) == 0:
    print('Waiting for job to complete')

    # Poll job till its complete
    job_url = job_url_template.format(str(job_id))
    job_finished = False

    while not job_finished:
        r = requests.get(job_url, headers=headers)

        if r.status_code == 200:
            json = r.json()
            status = json['status']

            if status == 'complete':
                archive_url = json['data']['url']
                job_finished = True
            elif status == 'running':
                print('Still waiting')
                time.sleep(job_poll_interval_secs)
            else:
                sys.exit(1)
        else:
            sys.exit(1)

# Remove all files from the snapshot directory 
print('Clearing snapshot directory')
shutil.rmtree(snapshot_path)
os.mkdir(snapshot_path)

# Download zip from JSON response
print('Download archive from {}'.format(archive_url))
r = requests.get(archive_url)
z = zipfile.ZipFile(io.BytesIO(r.content))

# Unzip the archive
print('Unzipping archive')
z.extractall(snapshot_path)

To download a hostable version (basically ‘build’ the project) Same thing, it is very specific to my folder structure:

import sys
import requests
import time
import subprocess
import os
import shutil
import zipfile
import io
import re

FNULL = open(os.devnull, 'w')

build_path = '../build'
export_url = 'https://playcanvas.com/api/apps/download'
job_url_template = 'https://playcanvas.com/api/jobs/{}'

headers = {
    'Authorization':'Bearer kldsjfklfjkdfjdklsfjdslfdk',
    'Content-Type':'application/json'
}

data = '{"project_id":475452, "name":"Iso Base Builder", "scripts_concatenate":true }'

job_poll_interval_secs = 1

job_id = -1
download_url = ''

# Request the download of the project
print('Requesting project download job')
r = requests.post(export_url, headers=headers, data=data)

if r.status_code == 201:
    json = r.json()
    status = json['status']

    if status == 'running':
        job_id = json['id']
    elif status == 'complete':
        download_url = json['url']
    else:
        sys.exit(1)

else:
    print('Error: {}'.format(r.status_code))
    sys.exit(1)

if len(download_url) == 0:
    print('Waiting for job to complete')

    # Poll job till its complete
    job_url = job_url_template.format(str(job_id))
    job_finished = False

    while not job_finished:
        r = requests.get(job_url, headers=headers)

        if r.status_code == 200:
            json = r.json()
            status = json['status']

            if status == 'complete':
                download_url = json['data']['download_url']
                job_finished = True
            elif status == 'running':
                print('Still waiting')
                time.sleep(job_poll_interval_secs)
            else:
                sys.exit(1)
        else:
            sys.exit(1)

# Remove all files from the snapshot directory 
print('Clearing snapshot directory')
shutil.rmtree(build_path)
os.mkdir(build_path)

# Download zip from JSON response
print('Download archive from {}'.format(download_url))
r = requests.get(download_url)
z = zipfile.ZipFile(io.BytesIO(r.content))

# Unzip the archive
print('Unzipping archive')
z.extractall(build_path)
1 Like

Thanks yaustar, I will look into that

THere really needs to be an undo function for accidental folder deletion, the highlights being dark on dark don’t make it clear when you make a mistake. if you you aren’t backing up all the time it’s a ral pain to deal with

Hi Will, I need to download this previous build because I messed up and deleted code. This is the URL of it: https://playcanv.as/b/OZ9hSF2P/

Here are your scripts:

https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/OZ9hSF2P/__game-scripts.js

You can see that listed in the Network panel in Chrome Dev Tools. Just pretty print that and grab the code you accidentally deleted.

BTW, you might want to consider using the Checkpointing feature. :slight_smile:

Thank you Will, I learned about it too late n.n"" but now I will use it constantly