Commit
·
604ab87
1
Parent(s):
88700c2
feat: add custom unique filename when doanload as zip
Browse files- app/lib/stores/workbench.ts +18 -1
app/lib/stores/workbench.ts
CHANGED
@@ -15,6 +15,7 @@ import { Octokit, type RestEndpointMethodTypes } from "@octokit/rest";
|
|
15 |
import * as nodePath from 'node:path';
|
16 |
import type { WebContainerProcess } from '@webcontainer/api';
|
17 |
import { extractRelativePath } from '~/utils/diff';
|
|
|
18 |
|
19 |
export interface ArtifactState {
|
20 |
id: string;
|
@@ -171,6 +172,7 @@ export class WorkbenchStore {
|
|
171 |
this.#editorStore.setSelectedFile(filePath);
|
172 |
}
|
173 |
|
|
|
174 |
async saveFile(filePath: string) {
|
175 |
const documents = this.#editorStore.documents.get();
|
176 |
const document = documents[filePath];
|
@@ -325,6 +327,15 @@ export class WorkbenchStore {
|
|
325 |
async downloadZip() {
|
326 |
const zip = new JSZip();
|
327 |
const files = this.files.get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
|
329 |
for (const [filePath, dirent] of Object.entries(files)) {
|
330 |
if (dirent?.type === 'file' && !dirent.isBinary) {
|
@@ -348,8 +359,14 @@ export class WorkbenchStore {
|
|
348 |
}
|
349 |
}
|
350 |
|
|
|
|
|
|
|
|
|
|
|
351 |
const content = await zip.generateAsync({ type: 'blob' });
|
352 |
-
saveAs(content,
|
|
|
353 |
}
|
354 |
|
355 |
async syncFiles(targetHandle: FileSystemDirectoryHandle) {
|
|
|
15 |
import * as nodePath from 'node:path';
|
16 |
import type { WebContainerProcess } from '@webcontainer/api';
|
17 |
import { extractRelativePath } from '~/utils/diff';
|
18 |
+
import { description } from '../persistence';
|
19 |
|
20 |
export interface ArtifactState {
|
21 |
id: string;
|
|
|
172 |
this.#editorStore.setSelectedFile(filePath);
|
173 |
}
|
174 |
|
175 |
+
|
176 |
async saveFile(filePath: string) {
|
177 |
const documents = this.#editorStore.documents.get();
|
178 |
const document = documents[filePath];
|
|
|
327 |
async downloadZip() {
|
328 |
const zip = new JSZip();
|
329 |
const files = this.files.get();
|
330 |
+
// Get the project name (assuming it's stored in this.projectName)
|
331 |
+
const projectName = (description.value ?? 'project').toLocaleLowerCase().split(' ').join('_');
|
332 |
+
|
333 |
+
// Generate a simple 6-character hash based on the current timestamp
|
334 |
+
const timestampHash = Date.now().toString(36).slice(-6);
|
335 |
+
const uniqueProjectName = `${projectName}_${timestampHash}`;
|
336 |
+
|
337 |
+
// Prompt the user for a file name, prefilled with the project name
|
338 |
+
const fileName = prompt('Enter the file name', `${uniqueProjectName}.zip`);
|
339 |
|
340 |
for (const [filePath, dirent] of Object.entries(files)) {
|
341 |
if (dirent?.type === 'file' && !dirent.isBinary) {
|
|
|
359 |
}
|
360 |
}
|
361 |
|
362 |
+
|
363 |
+
|
364 |
+
|
365 |
+
if (fileName) {
|
366 |
+
// Generate the zip file and save it
|
367 |
const content = await zip.generateAsync({ type: 'blob' });
|
368 |
+
saveAs(content, fileName);
|
369 |
+
}
|
370 |
}
|
371 |
|
372 |
async syncFiles(targetHandle: FileSystemDirectoryHandle) {
|