parent
db8407c1c3
commit
561564a034
12 changed files with 1390 additions and 84 deletions
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@ |
|||||||
|
|
||||||
added 1 package, and audited 170 packages in 4s |
up to date, audited 256 packages in 4s |
||||||
|
|
||||||
25 packages are looking for funding |
28 packages are looking for funding |
||||||
run `npm fund` for details |
run `npm fund` for details |
||||||
|
|
||||||
found 0 vulnerabilities |
found 0 vulnerabilities |
||||||
|
|||||||
@ -1,10 +1,17 @@ |
|||||||
@import "tailwindcss"; |
@import "tailwindcss"; |
||||||
|
|
||||||
main { |
html{ |
||||||
@apply flex flex-col items-center justify-start min-h-screen gap-4 p-4; |
|
||||||
|
} |
||||||
|
main{ |
||||||
|
@apply w-full min-h-screen; |
||||||
|
} |
||||||
|
section { |
||||||
|
@apply flex flex-col items-center justify-center gap-4 p-4; |
||||||
|
@apply bg-gray-100 rounded-xl; |
||||||
} |
} |
||||||
button{ |
button{ |
||||||
@apply px-4 py-2 bg-fuchsia-400 text-black font-bold rounded hover:bg-fuchsia-500; |
@apply px-4 py-2 bg-fuchsia-400 text-black font-bold rounded-full hover:bg-fuchsia-500; |
||||||
} |
} |
||||||
select, input[type="file"] { |
select, input[type="file"] { |
||||||
@apply px-4 py-2 border border-gray-300 rounded; |
@apply px-4 py-2 border border-gray-300 rounded; |
||||||
|
|||||||
@ -0,0 +1,77 @@ |
|||||||
|
import { initializeApp } from "firebase/app"; |
||||||
|
import { getFirestore, collection, doc, deleteDoc, onSnapshot, setDoc } from "firebase/firestore"; |
||||||
|
|
||||||
|
const firebaseConfig = { |
||||||
|
apiKey: "AIzaSyD1VzUKXt0JskwyfjfIAbdROzPNB3fTIw0", |
||||||
|
authDomain: "uc-24070-thegreattipsy.firebaseapp.com", |
||||||
|
projectId: "uc-24070-thegreattipsy", |
||||||
|
storageBucket: "uc-24070-thegreattipsy.firebasestorage.app", |
||||||
|
messagingSenderId: "772804793020", |
||||||
|
appId: "1:772804793020:web:258003100900c20e0fb6b9", |
||||||
|
measurementId: "G-1CRHMJY4L9" |
||||||
|
}; |
||||||
|
|
||||||
|
// Initialize Firebase
|
||||||
|
const app = initializeApp(firebaseConfig); |
||||||
|
|
||||||
|
const CollectionName="prints"; |
||||||
|
|
||||||
|
export function listenToPrints(callback) { |
||||||
|
// Listen for changes in the prints collection
|
||||||
|
const db = getFirestore(app); |
||||||
|
const printsRef = collection(db, CollectionName); |
||||||
|
onSnapshot(printsRef, (snapshot) => { |
||||||
|
const prints = []; |
||||||
|
snapshot.forEach((doc) => { |
||||||
|
prints.push({ id: doc.id, ...doc.data() }); |
||||||
|
}); |
||||||
|
callback(prints); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
export function clearPrints() { |
||||||
|
// Clear the prints collection
|
||||||
|
const db = getFirestore(app); |
||||||
|
const printsRef = collection(db, CollectionName); |
||||||
|
onSnapshot(printsRef, (snapshot) => { |
||||||
|
snapshot.forEach((doc) => { |
||||||
|
// Assuming you have a delete function to remove documents
|
||||||
|
deleteDoc(doc.ref); |
||||||
|
}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
export function deletePrint(id) { |
||||||
|
// Delete a specific print by id
|
||||||
|
const db = getFirestore(app); |
||||||
|
const printRef = doc(collection(db, CollectionName), id); |
||||||
|
|
||||||
|
deleteDoc(printRef) |
||||||
|
.then(() => { |
||||||
|
console.log(`Print with id ${id} deleted successfully.`); |
||||||
|
}) |
||||||
|
.catch((error) => {
|
||||||
|
console.error(`Error deleting print with id ${id}:`, error); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
export function createTestFile(){ |
||||||
|
// Create a test print file
|
||||||
|
const db = getFirestore(app); |
||||||
|
|
||||||
|
const testPrint = { |
||||||
|
url: "https://s3.ap-northeast-2.amazonaws.com/ultracombos.project/24070-%E5%BE%AE%E9%86%BA%E5%A4%A7%E9%A3%AF%E5%BA%97%E9%AB%98%E9%9B%84%E7%89%88/Postcard-01.png", |
||||||
|
createdAt: new Date().toISOString(), |
||||||
|
id: `test-${Date.now()}`, |
||||||
|
status: "pending" |
||||||
|
}; |
||||||
|
|
||||||
|
// Add the test print to the collection
|
||||||
|
setDoc(doc(db, CollectionName, testPrint.id), testPrint) |
||||||
|
.then(() => { |
||||||
|
console.log("Test print created successfully."); |
||||||
|
}) |
||||||
|
.catch((error) => { |
||||||
|
console.error("Error creating test print:", error); |
||||||
|
}); |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
import { writeFile, BaseDirectory, exists, mkdir } from '@tauri-apps/plugin-fs'; |
||||||
|
import { path } from '@tauri-apps/api'; |
||||||
|
|
||||||
|
const OutputDir = 'prints'; |
||||||
|
|
||||||
|
export async function saveToDisk(id, url){ |
||||||
|
|
||||||
|
console.log("Saving file to disk:", id, url); |
||||||
|
|
||||||
|
const response = await fetch(url); |
||||||
|
const arrayBuffer = await response.arrayBuffer(); |
||||||
|
|
||||||
|
const base=BaseDirectory.Document; |
||||||
|
const folder=`${OutputDir}`; |
||||||
|
const filePath = `${folder}/${id}.png`; |
||||||
|
|
||||||
|
|
||||||
|
// Check if the directory exists, if not create it
|
||||||
|
const dirExists = await exists(folder, { baseDir: base }); |
||||||
|
if (!dirExists) { |
||||||
|
console.log("Directory does not exist, creating:", folder); |
||||||
|
await mkdir(folder, { baseDir: base }); |
||||||
|
} |
||||||
|
|
||||||
|
// Write the file to the disk
|
||||||
|
await writeFile(filePath, arrayBuffer, { baseDir: base }); |
||||||
|
|
||||||
|
return `${await path.documentDir()}\\${filePath}`; |
||||||
|
} |
||||||
Loading…
Reference in new issue