PLEC Update

- Append timestamp to avoid filename conflicts
- Start on workspace/dist/ folder or workspace/
This commit is contained in:
2026-05-08 10:36:44 +08:00
parent b87ba579a5
commit e42002f5de
3 changed files with 31 additions and 28 deletions

View File

@@ -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"

View File

@@ -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<string>('uploadUrl')!;
const originUrl = cfg.get<string>('originUrl')!;
const previewBase = cfg.get<string>('previewBase')!;
const skipExistsCheck = cfg.get<boolean>('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<boolean | null> {
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 {