|
@@ -45,6 +45,7 @@ export interface ShopContent {
|
|
|
changed: boolean; // true if content changed from previous scrape
|
|
changed: boolean; // true if content changed from previous scrape
|
|
|
created_at: string;
|
|
created_at: string;
|
|
|
updated_at: string;
|
|
updated_at: string;
|
|
|
|
|
+ title: string | null; // Page title from <title> tag
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface ShopContentWithResults extends ShopContent {
|
|
export interface ShopContentWithResults extends ShopContent {
|
|
@@ -175,10 +176,18 @@ export class ShopDatabase {
|
|
|
changed INTEGER DEFAULT 0,
|
|
changed INTEGER DEFAULT 0,
|
|
|
created_at TEXT NOT NULL,
|
|
created_at TEXT NOT NULL,
|
|
|
updated_at TEXT NOT NULL,
|
|
updated_at TEXT NOT NULL,
|
|
|
|
|
+ title TEXT,
|
|
|
FOREIGN KEY (shop_id) REFERENCES shops(id) ON DELETE CASCADE
|
|
FOREIGN KEY (shop_id) REFERENCES shops(id) ON DELETE CASCADE
|
|
|
)
|
|
)
|
|
|
`);
|
|
`);
|
|
|
|
|
|
|
|
|
|
+ // Add title column to existing databases (migration)
|
|
|
|
|
+ try {
|
|
|
|
|
+ this.db.exec(`ALTER TABLE shop_content ADD COLUMN title TEXT`);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ // Column might already exist, ignore error
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Create index on shop_content for faster lookups
|
|
// Create index on shop_content for faster lookups
|
|
|
this.db.exec(`
|
|
this.db.exec(`
|
|
|
CREATE INDEX IF NOT EXISTS idx_shop_content_shop_type
|
|
CREATE INDEX IF NOT EXISTS idx_shop_content_shop_type
|
|
@@ -449,7 +458,8 @@ export class ShopDatabase {
|
|
|
shopId: string,
|
|
shopId: string,
|
|
|
contentType: 'shipping' | 'contacts' | 'terms' | 'faq',
|
|
contentType: 'shipping' | 'contacts' | 'terms' | 'faq',
|
|
|
url: string,
|
|
url: string,
|
|
|
- content: string
|
|
|
|
|
|
|
+ content: string,
|
|
|
|
|
+ title?: string
|
|
|
): { changed: boolean; contentId: string } {
|
|
): { changed: boolean; contentId: string } {
|
|
|
const crypto = require('crypto');
|
|
const crypto = require('crypto');
|
|
|
const contentHash = crypto.createHash('md5').update(content).digest('hex');
|
|
const contentHash = crypto.createHash('md5').update(content).digest('hex');
|
|
@@ -468,9 +478,9 @@ export class ShopDatabase {
|
|
|
|
|
|
|
|
// Insert new content record
|
|
// Insert new content record
|
|
|
this.db.prepare(`
|
|
this.db.prepare(`
|
|
|
- INSERT INTO shop_content (id, shop_id, content_type, url, content, content_hash, changed, created_at, updated_at)
|
|
|
|
|
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
- `).run(id, shopId, contentType, url, content, contentHash, changed ? 1 : 0, now, now);
|
|
|
|
|
|
|
+ INSERT INTO shop_content (id, shop_id, content_type, url, content, content_hash, changed, created_at, updated_at, title)
|
|
|
|
|
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
+ `).run(id, shopId, contentType, url, content, contentHash, changed ? 1 : 0, now, now, title || null);
|
|
|
|
|
|
|
|
if (changed) {
|
|
if (changed) {
|
|
|
logger.info(`Content changed detected for ${contentType} in shop ${shopId}`);
|
|
logger.info(`Content changed detected for ${contentType} in shop ${shopId}`);
|