88 lines
No EOL
2.8 KiB
TypeScript
88 lines
No EOL
2.8 KiB
TypeScript
import PocketBase from 'pocketbase';
|
|
|
|
const LOCAL_PB_URL = 'http://127.0.0.1:8090';
|
|
const REMOTE_PB_URL = 'https://avt-back.ru';
|
|
const ADMIN_EMAIL = 'redibedi2019@gmail.com';
|
|
const ADMIN_PASSWORD = 'Stalin4444';
|
|
|
|
const localPb = new PocketBase(LOCAL_PB_URL);
|
|
const remotePb = new PocketBase(REMOTE_PB_URL);
|
|
|
|
interface Post {
|
|
id: string;
|
|
title: string;
|
|
content: string;
|
|
slug: string;
|
|
description: string;
|
|
}
|
|
|
|
const REMOTE_IDS: Record<string, string> = {
|
|
'skrytie-s-mesta-dtp': 'e8or2rfsrpoly19',
|
|
'prezumpciya-nevinovnosti-voditelya': 'sdthyq0xurxxzfw',
|
|
'otkaz-ot-podpisi-v-protokole-gibdd': 'no247l14oxw156i',
|
|
'lekarstva-za-rulem-lishenie-prav': 'eflpgypt1r78q3q',
|
|
'lishenie-prav-za-vstrechku-12-15': 'kmt2cpiu47jsp9c',
|
|
'nezavisimaya-ekspertiza-posle-dtp': '87u3tnboztln5w1',
|
|
'kak-priostanovit-protokol-gibdd': 'at22ktwu6u1x5u1',
|
|
'avtoyurist-surgut-besplatnaya-konsultaciya': 'ewq7fbjbgpo12iv',
|
|
'kak-pravilno-zapolnyat-admin-protokol-gibdd': 'kqh8f6py72yemhl',
|
|
'protocol-ili-postanovlenie': '656dhm888yebhc8',
|
|
'5-oshibok-voditelya-pri-zapolnenii-protokola-gibdd': 'f54gic3amc1rmjx',
|
|
};
|
|
|
|
async function syncPosts() {
|
|
console.log('🔄 Синхронизация постов\n');
|
|
console.log('='.repeat(60));
|
|
|
|
// Try to auth as user on remote
|
|
try {
|
|
await remotePb.collection('users').authWithPassword(ADMIN_EMAIL, ADMIN_PASSWORD);
|
|
console.log('✓ Авторизован на remote\n');
|
|
} catch (error: any) {
|
|
console.log('⚠ Ошибка авторизации:', error.message);
|
|
console.log('Пробуем через admins auth...\n');
|
|
|
|
try {
|
|
await remotePb.admins.authWithPassword(ADMIN_EMAIL, ADMIN_PASSWORD);
|
|
console.log('✓ Авторизован через admin\n');
|
|
} catch (e2: any) {
|
|
console.log('⚠ Admin auth тоже не работает:', e2.message);
|
|
}
|
|
}
|
|
|
|
const localPosts = await localPb.collection('posts').getList(1, 500);
|
|
const localList = localPosts.items as unknown as Post[];
|
|
|
|
console.log(`Локально постов: ${localList.length}`);
|
|
console.log(`Авторизован: ${remotePb.authStore.isValid}\n`);
|
|
|
|
let synced = 0;
|
|
let failed = 0;
|
|
|
|
for (const post of localList) {
|
|
const remoteId = REMOTE_IDS[post.slug];
|
|
|
|
if (!remoteId) {
|
|
failed++;
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
await remotePb.collection('posts').update(remoteId, {
|
|
content: post.content,
|
|
description: post.description,
|
|
});
|
|
|
|
console.log(`✓ ${post.slug}`);
|
|
synced++;
|
|
} catch (error: any) {
|
|
console.error(`✗ ${post.slug}: ${error.message}`);
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log(`Результат: синхронизировано ${synced}, ошибок ${failed}`);
|
|
}
|
|
|
|
syncPosts(); |