mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-19 13:08:12 +02:00
feat: add core API routes for authentication, user management, and file upload handling.
This commit is contained in:
1 parent
84d2012929
commit
4e189e7797
1 file changed
+37
-1
+37
-1
@@ -3,7 +3,7 @@ import { createServer, type Server } from "http";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import { storage } from "./storage";
|
import { storage } from "./storage";
|
||||||
import { db } from "./db";
|
import { db, pool } from "./db";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import passport from "./auth";
|
import passport from "./auth";
|
||||||
@@ -1032,6 +1032,42 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Route admin : correction des titres corrompus (latin1 lu comme UTF-8)
|
||||||
|
// Se déclenche aussi automatiquement au démarrage
|
||||||
|
const fixAudioTrackEncoding = async () => {
|
||||||
|
try {
|
||||||
|
const tracks = await storage.getAudioTracks();
|
||||||
|
let fixed = 0;
|
||||||
|
for (const track of tracks) {
|
||||||
|
// Détecte les séquences typiques latin1/utf8 mal interprétées (ex: é, à , è)
|
||||||
|
if (/[\xC0-\xC3][\x80-\xBF]/.test(track.title)) {
|
||||||
|
const corrected = Buffer.from(track.title, 'latin1').toString('utf8');
|
||||||
|
const correctedFileName = Buffer.from(track.fileName, 'latin1').toString('utf8');
|
||||||
|
await pool.query(
|
||||||
|
`UPDATE audio_tracks SET title = $1, file_name = $2 WHERE id = $3`,
|
||||||
|
[corrected, correctedFileName, track.id]
|
||||||
|
);
|
||||||
|
fixed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fixed > 0) console.log(`🎵 Fixed encoding for ${fixed} audio track(s).`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error fixing audio track encoding:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Lancer la correction au démarrage
|
||||||
|
fixAudioTrackEncoding().catch(() => { });
|
||||||
|
|
||||||
|
app.post("/api/audio-tracks/fix-encoding", requireAdmin, async (req, res) => {
|
||||||
|
try {
|
||||||
|
await fixAudioTrackEncoding();
|
||||||
|
const tracks = await storage.getAudioTracks();
|
||||||
|
res.json({ success: true, tracks });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: "Failed to fix encoding" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/api/audio-tracks", requireAuth, async (req, res) => {
|
app.get("/api/audio-tracks", requireAuth, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Both admin and regular users can list audio tracks (to pick them for reels)
|
// Both admin and regular users can list audio tracks (to pick them for reels)
|
||||||
|
|||||||
Reference in new issue
Block a user