Download src/lib/icon.js from no1b4me/statslist: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/no1b4me/statslist/resolve/main/src/lib/icon.js
- Command line
-
hf download hf://spaces/no1b4me/statslist/src/lib/icon.js
-
curl -L -o icon.js https://huggingface.co/spaces/no1b4me/statslist/resolve/main/src/lib/icon.js
1.3 kB
| import { writeFile, readFile } from 'node:fs/promises'; | |
| import path from 'path'; | |
| import config from './config.js'; | |
| let ICON_LOCATION = path.join(import.meta.dirname, '../static/img/icon.png'); | |
| export async function download(){ | |
| const res = await fetch(config.addonIcon, {method: 'GET'}); | |
| if(!res.ok){ | |
| throw new Error('Network response was not ok'); | |
| } | |
| let extension = null; | |
| if(res.headers.has('content-type')){ | |
| const matches = res.headers.get('content-type').match(/image\/([a-z0-9]+)/i); | |
| if(matches && matches.length > 1)extension = matches[1]; | |
| } | |
| if(!extension && res.headers.has('content-disposition')){ | |
| const matches = res.headers.get('content-disposition').match(/filename\*?=['"]?(?:UTF-\d['"]*)?([^;\r\n"']*)['"]?;?/i); | |
| if(matches && matches.length > 1)extension = matches[1].split('.').pop(); | |
| } | |
| if(!extension){ | |
| throw new Error(`No valid image found: ${res.headers.get('content-type')} / ${res.headers.get('content-disposition')}`); | |
| } | |
| const location = `${config.dataFolder}/icon.${extension}`; | |
| const buffer = await res.arrayBuffer(); | |
| await writeFile(location, new Uint8Array(buffer)); | |
| console.log(`Icon downloaded: ${location}`); | |
| ICON_LOCATION = location; | |
| return location; | |
| } | |
| export async function getLocation(){ | |
| return ICON_LOCATION; | |
| } |