fix: Supabase storage upload hatasını çözmek için dosya adlarındaki Türkçe karakterler ve boşluklar temizlendi
This commit is contained in:
@@ -389,7 +389,13 @@ export const uploadDocument = async (req: AuthenticatedRequest, res: Response) =
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Upload File to Supabase Storage
|
// 2. Upload File to Supabase Storage
|
||||||
const filePath = `${user_id}/${Date.now()}_${file.originalname}`;
|
const sanitizeFilename = (name: string) => {
|
||||||
|
const charMap: Record<string, string> = { 'ç': 'c', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u', 'Ç': 'C', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U' };
|
||||||
|
const engName = name.replace(/[çğıöşüÇĞİÖŞÜ]/g, m => charMap[m]);
|
||||||
|
return engName.replace(/[^a-zA-Z0-9.\-_]/g, '_');
|
||||||
|
};
|
||||||
|
const safeName = sanitizeFilename(file.originalname);
|
||||||
|
const filePath = `${user_id}/${Date.now()}_${safeName}`;
|
||||||
const { error: uploadError } = await supabase.storage
|
const { error: uploadError } = await supabase.storage
|
||||||
.from('case-documents')
|
.from('case-documents')
|
||||||
.upload(filePath, file.buffer, {
|
.upload(filePath, file.buffer, {
|
||||||
|
|||||||
@@ -29,7 +29,14 @@ export const uploadTemplate = async (req: AuthenticatedRequest, res: Response) =
|
|||||||
console.error('Template Text Extraction Error:', err);
|
console.error('Template Text Extraction Error:', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const storagePath = `templates/${userId}/${Date.now()}_${file.originalname}`;
|
const sanitizeFilename = (name: string) => {
|
||||||
|
const charMap: Record<string, string> = { 'ç': 'c', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u', 'Ç': 'C', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U' };
|
||||||
|
const engName = name.replace(/[çğıöşüÇĞİÖŞÜ]/g, m => charMap[m]);
|
||||||
|
return engName.replace(/[^a-zA-Z0-9.\-_]/g, '_');
|
||||||
|
};
|
||||||
|
|
||||||
|
const safeName = sanitizeFilename(file.originalname);
|
||||||
|
const storagePath = `templates/${userId}/${Date.now()}_${safeName}`;
|
||||||
const { error: uploadError } = await supabase.storage
|
const { error: uploadError } = await supabase.storage
|
||||||
.from('case-documents')
|
.from('case-documents')
|
||||||
.upload(storagePath, file.buffer, { contentType: file.mimetype });
|
.upload(storagePath, file.buffer, { contentType: file.mimetype });
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
require('dotenv').config();
|
||||||
|
const { createClient } = require('@supabase/supabase-js');
|
||||||
|
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_ROLE_KEY);
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const { data, error } = await supabase.from('templates').select('*').limit(1);
|
||||||
|
if (error) console.error('Error:', error.message);
|
||||||
|
else console.log('Success:', data);
|
||||||
|
}
|
||||||
|
run();
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
require('dotenv').config();
|
||||||
|
const { createClient } = require('@supabase/supabase-js');
|
||||||
|
const supabaseUrl = process.env.SUPABASE_URL;
|
||||||
|
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_ANON_KEY;
|
||||||
|
const supabase = createClient(supabaseUrl, supabaseKey);
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const { data, error } = await supabase.storage.from('case-documents').upload('templates/test_user_id/test.txt', Buffer.from('hello'), { contentType: 'text/plain' });
|
||||||
|
if (error) console.error('Error:', error);
|
||||||
|
else console.log('Success:', data);
|
||||||
|
}
|
||||||
|
run();
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
require('dotenv').config();
|
||||||
|
const { createClient } = require('@supabase/supabase-js');
|
||||||
|
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_ROLE_KEY);
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const { data, error } = await supabase.storage.from('case-documents').upload('templates/test_user_id/şablon dosyası.udf', Buffer.from('hello'), { contentType: 'application/octet-stream' });
|
||||||
|
if (error) console.error('Error:', error);
|
||||||
|
else console.log('Success:', data);
|
||||||
|
}
|
||||||
|
run();
|
||||||
Reference in New Issue
Block a user