CDN working with Docker
This commit is contained in:
+9
-1
@@ -6,20 +6,26 @@ export default function UploadStudents() {
|
||||
const statusMessage = useSignal<string>("");
|
||||
const fileData = useSignal<File | null>(null);
|
||||
|
||||
console.log("Component UploadStudents mounted");
|
||||
|
||||
const handleFileChange = (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
if (input.files && input.files.length > 0) {
|
||||
fileData.value = input.files[0];
|
||||
statusMessage.value = "File selected: " + input.files[0].name;
|
||||
console.log("File selected:", input.files[0].name);
|
||||
} else {
|
||||
fileData.value = null;
|
||||
statusMessage.value = "No file selected";
|
||||
console.log("No file selected.");
|
||||
}
|
||||
};
|
||||
|
||||
const confirmUpload = async () => {
|
||||
console.log("Confirm Upload clicked");
|
||||
if (!fileData.value) {
|
||||
statusMessage.value = "Please select a file before confirming upload.";
|
||||
console.error("Error: No file selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,10 +40,12 @@ export default function UploadStudents() {
|
||||
for (const sheetName of workbook.SheetNames) {
|
||||
const sheet = workbook.Sheets[sheetName];
|
||||
const data = XLSX.utils.sheet_to_json(sheet, {
|
||||
header: ["Nom", "Prénom", "Mail"],
|
||||
header: ["Nom", "Prénom", "Mail"],
|
||||
range: 1, // Ignorer les en-têtes
|
||||
});
|
||||
|
||||
console.log(`Data from sheet ${sheetName}:`, data);
|
||||
|
||||
const response = await fetch("/api/insert_students", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@@ -4,10 +4,8 @@ import { Database } from "@db/sqlite";
|
||||
export const handler: Handlers = {
|
||||
async GET(_request, context) {
|
||||
try {
|
||||
// Ouvre ou crée la base de données SQLite
|
||||
const db = new Database("databases/data/mobility.db");
|
||||
|
||||
// Crée la table si elle n'existe pas
|
||||
db.execute(`
|
||||
CREATE TABLE IF NOT EXISTS students (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -18,7 +16,6 @@ export const handler: Handlers = {
|
||||
);
|
||||
`);
|
||||
|
||||
// Récupère toutes les données
|
||||
const students = [];
|
||||
for (const [id, firstName, lastName, email, promotion] of db.query(
|
||||
"SELECT id, firstName, lastName, email, promotion FROM students"
|
||||
@@ -43,10 +40,8 @@ export const handler: Handlers = {
|
||||
const body = await request.json();
|
||||
const { data, promoName } = body;
|
||||
|
||||
// Ouvre ou crée la base de données SQLite
|
||||
const db = new Database("databases/data/mobility.db");
|
||||
|
||||
// Crée la table si elle n'existe pas
|
||||
db.execute(`
|
||||
CREATE TABLE IF NOT EXISTS students (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -57,7 +52,6 @@ export const handler: Handlers = {
|
||||
);
|
||||
`);
|
||||
|
||||
// Prépare et insère les données
|
||||
const insertQuery =
|
||||
"INSERT INTO students (firstName, lastName, email, promotion) VALUES (?, ?, ?, ?)";
|
||||
for (const student of data) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { RouteConfig } from "$fresh/server.ts";
|
||||
import UploadStudents from "../(_components)/UploadStudents.tsx";
|
||||
import UploadStudents from "../(_islands)/UploadStudents.tsx";
|
||||
//import ConsultStudents from "../(_components)/ConsultStudents.tsx";
|
||||
//import EditStudents from "../(_components)/EditStudents.tsx";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user