From a3f8679f971cb277864552569b2d3a4a667b2eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20F?= Date: Mon, 28 Aug 2023 10:18:34 +0200 Subject: [PATCH] publish VSIX --- .github/workflows/ci.yml | 2 ++ extension/main.js | 18 +++++++++++++----- extension/webview.html | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26a417c..39f62dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: - name: check key extract run: | [ "$(DZR_CBC= ./dzr ! 2>/dev/null | sha1sum)" = '3ad58d9232a3745ad9308b0669c83b6f7e8dba4d -' ] + - name: bundle VSIX + run: zip -r $(jq -r '.name+"-"+.version+".vsix"' < extension/package.json) extension - name: publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/extension/main.js b/extension/main.js index 59c19fe..a47b34b 100644 --- a/extension/main.js +++ b/extension/main.js @@ -14,6 +14,7 @@ const type2icon = { user: '$(account) ', }; const hhmmss = (s) => (new Date(s * 1000)).toISOString().slice(11, 19).replace(/^00:/, ''); +const wait = (ms=1000) => new Promise(resolve => setTimeout(resolve, ms)); // still no fetch() in 2023 ? const fetch = (url, opt, data) => new Promise((resolve, reject) => { const chunks = [], req = https.request(url, opt, res => { @@ -90,7 +91,7 @@ async function browse(url_or_event, label) { } } catch (e) { console.error(e) } } - +/* songs may came from API (full info) or storage (light info) */ const with_url = async (songs) => songs?.length ? await vscode.window.withProgress({ title: 'Fetching Song Info...', location }, async (progress) => { try { const next = (val) => (progress.report({ increment: 100 / 4 }), val); @@ -107,9 +108,12 @@ const with_url = async (songs) => songs?.length ? await vscode.window.withProgre })))); const errors = URL_NFO.data.map((nfo, i) => [nfo.errors, songs[i]]).filter(([err]) => err).map(([[err], sng]) => `${sng.title}: ${err.message} (${err.code})`).join('\n'); if (errors) setTimeout(() => vscode.window.showWarningMessage(errors), 500); // can't warn while progress ? - return songs.map(({ id, title_short, title_version, artist, contributors, duration }, i) => ({ - id, title: title_short.replace(/ ?\(feat.*?\)/, ''), version: title_version, duration, - artists: (contributors || [artist])?.map(({ id, name }) => ({ id, name })), + return songs.map(({/* api :*/ id, md5_image, duration, title_short, title_version, artist, contributors, + /*cache:*/ title, version, artists }, i) => ({ + id, md5_image, duration, + title: title_short?.replace(/ ?\(feat.*?\)/, '') || title, + version: title_version || version, + artists: artists??(contributors || [artist])?.map(({ id, name }) => ({ id, name })), size: +SNG_NFO.data[i].FILESIZE, expire: SNG_NFO.data[i].TRACK_TOKEN_EXPIRE, url: URL_NFO.data[i].media?.[0]?.sources?.[0]?.url @@ -257,7 +261,11 @@ exports.activate = async function (/**@type {vscode.ExtensionContext}*/ context) item && vscode.commands.executeCommand('dzr.load', item); }), vscode.commands.registerCommand("dzr.load", async (item) => { - if (item.expire > new Date()/1000) { + if (!dzr.state.ready) { + vscode.commands.executeCommand('dzr.show'); + while (!dzr.state.ready) await wait(); + } + if (item.expire < (new Date()/1000)) { with_url(dzr.state.queue);//TODO: hope item is now up to date } const hex = (str) => str.split('').map(c => c.charCodeAt(0)) diff --git a/extension/webview.html b/extension/webview.html index 112a260..babc3a5 100644 --- a/extension/webview.html +++ b/extension/webview.html @@ -22,7 +22,7 @@

Disclamer

let mediaSource, sourceBuffer; const on = {// event from VSCode async open(item) { - img.src = "https://api.deezer.com/cover/"+item.id; + img.src = `https://e-cdns-images.dzcdn.net/images/cover/${item.md5_image}/1000x1000-000000-80-0-0.jpg`; mediaSource = new window.MediaSource(); audio.src = window.URL.createObjectURL(mediaSource); await new Promise(then => mediaSource.onsourceopen = () => then());