diff --git a/hpl-toolbox-0.1.0.vsix b/hpl-toolbox-0.1.1.vsix similarity index 73% rename from hpl-toolbox-0.1.0.vsix rename to hpl-toolbox-0.1.1.vsix index dc3ad22..6347af2 100644 Binary files a/hpl-toolbox-0.1.0.vsix and b/hpl-toolbox-0.1.1.vsix differ diff --git a/package.json b/package.json index 924220e..0aea6b0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "hpl-toolbox", "displayName": "HPL Toolbox", "description": "Bundled tools: PLEC Upload, AppLovin Demo Upload, Base64 Asset Scanner, Daily Update.", - "version": "0.1.0", + "version": "0.1.1", "publisher": "hesukastro", "engines": { "vscode": "^1.85.0" diff --git a/src/tools/plecUpload.ts b/src/tools/plecUpload.ts index 6cc6df8..2104147 100644 --- a/src/tools/plecUpload.ts +++ b/src/tools/plecUpload.ts @@ -20,6 +20,7 @@ export function openPlecUpload(_context: vscode.ExtensionContext) { canSelectMany: false, filters: { HTML: ['html', 'htm'] }, openLabel: 'Select', + defaultUri: getPickerDefaultUri(), }); if (picked && picked[0]) { const fp = picked[0].fsPath; @@ -53,8 +54,6 @@ async function handleUpload(panel: vscode.WebviewPanel, rows: UploadRow[]) { const cfg = vscode.workspace.getConfiguration('hplToolbox.plec'); const uploadUrl = cfg.get('uploadUrl')!; const originUrl = cfg.get('originUrl')!; - const previewBase = cfg.get('previewBase')!; - const skipExistsCheck = cfg.get('skipExistsCheck')!; const valid: UploadRow[] = []; for (const r of rows) { @@ -77,22 +76,8 @@ async function handleUpload(panel: vscode.WebviewPanel, rows: UploadRow[]) { return; } - panel.webview.postMessage({ type: 'status', message: 'Checking filename availability...' }); - - if (!skipExistsCheck) { - for (const r of valid) { - const fname = path.basename(r.path); - const exists = await checkFileExists(previewBase + encodeURIComponent(fname)); - if (exists === true) { - panel.webview.postMessage({ - type: 'rowError', - rowId: r.id, - message: `Filename "${fname}" already exists on preview server. Rename and retry.`, - }); - return; - } - } - } + const stamp = timestampSuffix(); + const stampedNames = valid.map((r) => appendTimestamp(path.basename(r.path), stamp)); panel.webview.postMessage({ type: 'status', message: 'Uploading...' }); @@ -101,7 +86,7 @@ async function handleUpload(panel: vscode.WebviewPanel, rows: UploadRow[]) { const r = valid[i]; const idx = i + 1; const buf = fs.readFileSync(r.path); - const file = new File([buf], path.basename(r.path), { type: 'text/html' }); + const file = new File([buf], stampedNames[i], { type: 'text/html' }); form.append(`fileUpload_${idx}`, file as any); form.append(`iterationNameUpload_${idx}`, encodeURI(r.iteration.replace(/\s+/g, ''))); } @@ -147,15 +132,33 @@ async function handleUpload(panel: vscode.WebviewPanel, rows: UploadRow[]) { panel.webview.postMessage({ type: 'result', preview, raw: json, rawText: text }); } -async function checkFileExists(url: string): Promise { - try { - const res = await fetch(url, { method: 'HEAD' }); - if (res.status === 200) return true; - if (res.status === 404) return false; - return null; - } catch { - return null; +function timestampSuffix(d: Date = new Date()): string { + const pad = (n: number, w = 2) => String(n).padStart(w, '0'); + return ( + d.getFullYear().toString() + + pad(d.getMonth() + 1) + + pad(d.getDate()) + + pad(d.getHours()) + + pad(d.getMinutes()) + + pad(d.getSeconds()) + ); +} + +function appendTimestamp(filename: string, stamp: string): string { + const ext = path.extname(filename); + const base = ext ? filename.slice(0, -ext.length) : filename; + return `${base}_${stamp}${ext}`; +} + +function getPickerDefaultUri(): vscode.Uri | undefined { + const folders = vscode.workspace.workspaceFolders; + if (!folders || folders.length === 0) return undefined; + const root = folders[0].uri.fsPath; + const dist = path.join(root, 'dist'); + if (fs.existsSync(dist) && fs.statSync(dist).isDirectory()) { + return vscode.Uri.file(dist); } + return vscode.Uri.file(root); } function getHtml(): string {