feat(sync): refonte import Takeout complet (playlists, musique, recherches, identité)
This commit is contained in:
@@ -40,6 +40,7 @@ import {
|
||||
cryptoRandomId,
|
||||
cryptoRandomUUID,
|
||||
insertSearchHistory,
|
||||
insertSearchHistoryAt,
|
||||
listSearchHistory,
|
||||
deleteSearchHistoryById,
|
||||
deleteAllSearchHistory,
|
||||
@@ -2550,6 +2551,28 @@ r.post('/user/history/search', authMiddleware, (req, res) => {
|
||||
return res.status(201).json(row);
|
||||
});
|
||||
|
||||
// Import en lot des recherches Takeout (historique-recherches.html).
|
||||
r.post('/user/history/search/batch', authMiddleware, oauthLimiter, (req, res) => {
|
||||
try {
|
||||
const items = Array.isArray(req.body?.items) ? req.body.items : [];
|
||||
if (!items.length) return res.status(400).json({ error: 'items_required' });
|
||||
if (items.length > 1000) return res.status(400).json({ error: 'batch_too_large' });
|
||||
let imported = 0;
|
||||
let skipped = 0;
|
||||
for (const it of items) {
|
||||
const query = String(it?.query || '').trim().slice(0, 300);
|
||||
if (!query) { skipped++; continue; }
|
||||
try {
|
||||
insertSearchHistoryAt({ userId: req.user.id, query, createdAt: it?.createdAt });
|
||||
imported++;
|
||||
} catch { skipped++; }
|
||||
}
|
||||
return res.json({ imported, skipped, total: items.length });
|
||||
} catch {
|
||||
return res.status(500).json({ error: 'search_batch_failed' });
|
||||
}
|
||||
});
|
||||
|
||||
r.get('/user/history/search', authMiddleware, (req, res) => {
|
||||
const limit = Math.min(200, Number(req.query.limit || 50));
|
||||
const before = req.query.before ? String(req.query.before) : undefined;
|
||||
|
||||
Reference in New Issue
Block a user