Skip to content

Instantly share code, notes, and snippets.

@owyongsk
Last active August 20, 2025 21:09
Show Gist options
  • Select an option

  • Save owyongsk/5078d63a6a5439d428dd44a6cc289983 to your computer and use it in GitHub Desktop.

Select an option

Save owyongsk/5078d63a6a5439d428dd44a6cc289983 to your computer and use it in GitHub Desktop.

Revisions

  1. owyongsk revised this gist Nov 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cf_chameleon.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    1. Create an app on your https://www.dropbox.com/developers/apps/create, choose "Dropbox API",
    set permissions to "Apps folder", generate a token Refresh until image loads
    2. Deploy this code to Cloudflare Workers.
    3. Set your token as env variable DROPBOX_TOKEN
    3. Set your token as env variable DROPBOX_TOKEN in Cloudflare worker
    4. Move all your files to your ~/Dropbox/Apps/'dropbox-app-name-earlier' folder
    5. Look at your file at https://example.com/path/to/file.html if you have a
    file ~/Dropbox/Apps/'dropbox-app-name-earlier'/path/to/file.html
  2. owyongsk revised this gist Nov 22, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions cf_chameleon.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,12 @@
    /***
    1. Create an app on your https://www.dropbox.com/developers/apps/create, choose "Dropbox API", set permissions to "Apps folder", generate a token Refresh until image loads
    1. Create an app on your https://www.dropbox.com/developers/apps/create, choose "Dropbox API",
    set permissions to "Apps folder", generate a token Refresh until image loads
    2. Deploy this code to Cloudflare Workers.
    3. Set your token as env variable DROPBOX_TOKEN
    4. Move all your files to your ~/Dropbox/Apps/'dropbox-app-name-earlier' folder
    5. Look at your file at https://example.com/path/to/file.html if you have a file ~/Dropbox/Apps/'dropbox-app-name-earlier'/path/to/file.html
    5. Look at your file at https://example.com/path/to/file.html if you have a
    file ~/Dropbox/Apps/'dropbox-app-name-earlier'/path/to/file.html
    ***/

  3. owyongsk revised this gist Nov 22, 2022. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions cf_chameleon.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    /***
    1. Create an app on your https://www.dropbox.com/developers/apps/create, choose "Dropbox API", set permissions to "Apps folder", generate a token Refresh until image loads
    2. Deploy this code to Cloudflare Workers.
    3. Set your token as env variable DROPBOX_TOKEN
    4. Move all your files to your ~/Dropbox/Apps/'dropbox-app-name-earlier' folder
    5. Look at your file at https://example.com/path/to/file.html if you have a file ~/Dropbox/Apps/'dropbox-app-name-earlier'/path/to/file.html
    1. Create an app on your https://www.dropbox.com/developers/apps/create, choose "Dropbox API", set permissions to "Apps folder", generate a token Refresh until image loads
    2. Deploy this code to Cloudflare Workers.
    3. Set your token as env variable DROPBOX_TOKEN
    4. Move all your files to your ~/Dropbox/Apps/'dropbox-app-name-earlier' folder
    5. Look at your file at https://example.com/path/to/file.html if you have a file ~/Dropbox/Apps/'dropbox-app-name-earlier'/path/to/file.html
    ***/

  4. owyongsk revised this gist Nov 22, 2022. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions cf_chameleon.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@
    /***
    1. Create an app on your https://www.dropbox.com/developers/apps/create, choose "Dropbox API", set permissions to "Apps folder", generate a token Refresh until image loads
    2. Deploy this code to Cloudflare Workers.
    3. Set your token as env variable DROPBOX_TOKEN
    4. Move all your files to your ~/Dropbox/Apps/'dropbox-app-name-earlier' folder
    5. Look at your file at https://example.com/path/to/file.html if you have a file ~/Dropbox/Apps/'dropbox-app-name-earlier'/path/to/file.html
    ***/

    export default {
    async fetch(request, env) {
    const path = new URL(request.url).pathname;
  5. owyongsk created this gist Nov 22, 2022.
    40 changes: 40 additions & 0 deletions cf_chameleon.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    export default {
    async fetch(request, env) {
    const path = new URL(request.url).pathname;

    // cf-connecting-ip header does not work in playground
    if (path == "/") return new Response(request.headers.get('cf-connecting-ip'))

    var response = await fetch('https://content.dropboxapi.com/2/files/download',{
    headers: {
    "Authorization": `Bearer ${env.DROPBOX_TOKEN}`,
    "Dropbox-API-Arg": `{\"path\": \"${path}\"}`
    }
    });

    const fileType = path.split(".").at(-1);

    const contentType = new Map([
    ['html','text/html'],
    ['txt', 'text/plain'],
    ['css', 'text/css'],
    ['js', 'text/javascript'],
    ['vtt', 'text/vtt'],
    ['jpg', 'image/jpeg'],
    ['jpeg','image/jpeg'],
    ['png', 'image/png'],
    ['ico', 'image/x-icon'],
    ['pdf', 'application/pdf'],
    ['json','application/json'],
    ]).get(fileType) || 'application/octet-stream'

    return new Response(
    response.body,
    {
    headers: new Headers({
    "content-type": contentType
    }),
    }
    )
    }
    }