@@ -28,20 +36,41 @@ const formattedText = computed(() => {
unknown date
archived {{ formattedDate(post.archivedAt) }}
-
\ No newline at end of file
diff --git a/archive-static-sites/facebook-archive/src/types.ts b/archive-static-sites/facebook-archive/src/types.ts
index 8ee738b8..9359f247 100644
--- a/archive-static-sites/facebook-archive/src/types.ts
+++ b/archive-static-sites/facebook-archive/src/types.ts
@@ -1,11 +1,18 @@
-export type Post = {
+export interface Post {
postID: string;
createdAt: string;
text: string;
title: string;
- archivedAt: string | null;
isReposted: boolean;
-};
+ archivedAt: string | null;
+ media?: {
+ mediaId: string;
+ type: string;
+ uri: string;
+ description: string | null;
+ createdAt: string | null;
+ }[];
+}
export type FacebookArchive = {
posts: Post[];
diff --git a/src/account_facebook/facebook_account_controller.ts b/src/account_facebook/facebook_account_controller.ts
index 990bbbdc..8de6f4ee 100644
--- a/src/account_facebook/facebook_account_controller.ts
+++ b/src/account_facebook/facebook_account_controller.ts
@@ -32,6 +32,8 @@ import {
FacebookJobRow,
convertFacebookJobRowToFacebookJob,
FacebookArchivePost,
+ FacebookArchiveMedia,
+ FacebookPostWithMedia,
FacebookPostRow
} from './types'
import * as FacebookArchiveTypes from '../../archive-static-sites/facebook-archive/src/types';
@@ -180,6 +182,22 @@ export class FacebookAccountController {
`ALTER TABLE post_new RENAME TO post;`
]
},
+ {
+ name: "20250302_add_media_table",
+ sql: [
+ `CREATE TABLE post_media (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ mediaId TEXT NOT NULL UNIQUE,
+ postId TEXT NOT NULL,
+ type TEXT NOT NULL,
+ uri TEXT NOT NULL,
+ description TEXT,
+ createdAt DATETIME,
+ addedToDatabaseAt DATETIME NOT NULL,
+ FOREIGN KEY(postId) REFERENCES post(postID)
+ );`
+ ]
+ },
])
log.info("FacebookAccountController.initDB: database initialized");
}
@@ -234,20 +252,44 @@ export class FacebookAccountController {
}
log.info("FacebookAccountController.archiveBuild: building archive");
-
- // Posts
- const posts: FacebookPostRow[] = exec(
+ // Posts with optional media
+ const postsFromDb = exec(
this.db,
- "SELECT * FROM post ORDER BY createdAt DESC",
+ `SELECT
+ p.*,
+ CASE
+ WHEN pm.mediaId IS NOT NULL
+ THEN GROUP_CONCAT(
+ json_object(
+ 'mediaId', pm.mediaId,
+ 'postId', pm.postId,
+ 'type', pm.type,
+ 'uri', pm.uri,
+ 'description', pm.description,
+ 'createdAt', pm.createdAt,
+ 'addedToDatabaseAt', pm.addedToDatabaseAt
+ )
+ )
+ ELSE NULL
+ END as media
+ FROM post p
+ LEFT JOIN post_media pm ON p.postID = pm.postId
+ GROUP BY p.postID
+ ORDER BY p.createdAt DESC`,
[],
"all"
- ) as FacebookPostRow[];
+ );
+ // Transform into FacebookPostWithMedia
+ const posts: FacebookPostWithMedia[] = (postsFromDb as Array