Merge pull request #9 from lassecapel/feat-add-custom-project-name

Feat add custom project name
This commit is contained in:
Dustin Loring 2024-12-01 07:06:58 -05:00 committed by GitHub
commit 88479fec94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,6 +14,7 @@ import { saveAs } from 'file-saver';
import { Octokit, type RestEndpointMethodTypes } from '@octokit/rest'; import { Octokit, type RestEndpointMethodTypes } from '@octokit/rest';
import * as nodePath from 'node:path'; import * as nodePath from 'node:path';
import { extractRelativePath } from '~/utils/diff'; import { extractRelativePath } from '~/utils/diff';
import { description } from '../persistence';
export interface ArtifactState { export interface ArtifactState {
id: string; id: string;
@ -168,6 +169,7 @@ export class WorkbenchStore {
this.#editorStore.setSelectedFile(filePath); this.#editorStore.setSelectedFile(filePath);
} }
async saveFile(filePath: string) { async saveFile(filePath: string) {
const documents = this.#editorStore.documents.get(); const documents = this.#editorStore.documents.get();
const document = documents[filePath]; const document = documents[filePath];
@ -327,6 +329,12 @@ export class WorkbenchStore {
async downloadZip() { async downloadZip() {
const zip = new JSZip(); const zip = new JSZip();
const files = this.files.get(); const files = this.files.get();
// Get the project name from the description input, or use a default name
const projectName = (description.value ?? 'project').toLocaleLowerCase().split(' ').join('_');
// Generate a simple 6-character hash based on the current timestamp
const timestampHash = Date.now().toString(36).slice(-6);
const uniqueProjectName = `${projectName}_${timestampHash}`;
for (const [filePath, dirent] of Object.entries(files)) { for (const [filePath, dirent] of Object.entries(files)) {
if (dirent?.type === 'file' && !dirent.isBinary) { if (dirent?.type === 'file' && !dirent.isBinary) {
@ -349,9 +357,10 @@ export class WorkbenchStore {
} }
} }
} }
// Generate the zip file and save it
const content = await zip.generateAsync({ type: 'blob' }); const content = await zip.generateAsync({ type: 'blob' });
saveAs(content, 'project.zip'); saveAs(content, `${uniqueProjectName}.zip`);
} }
async syncFiles(targetHandle: FileSystemDirectoryHandle) { async syncFiles(targetHandle: FileSystemDirectoryHandle) {