major update
backend
This commit is contained in:
1 parent
d39a941240
commit
234ed5989a
31 files changed
+1675
-208
No files matched your search
+52
-35
@@ -3,50 +3,67 @@
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "build/electron.js",
|
||||
"build": {
|
||||
"appId": "pl.mtps.messenger-archive"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn webpack",
|
||||
"start": "yarn electron . --trace-warnings --inspect",
|
||||
"dev": "yarn build --mode development && yarn start",
|
||||
"web": "yarn webpack-dev-server --config react.webpack.config.js",
|
||||
"dist": "# TODO: add electron-builder and github actions config"
|
||||
"build": "pnpm webpack",
|
||||
"start": "pnpm electron . --trace-warnings --inspect",
|
||||
"dev": "pnpm build --mode development && pnpm start",
|
||||
"web": "pnpm webpack-dev-server --config react.webpack.config.js",
|
||||
"dist": "# TODO: add electron-builder and github actions config",
|
||||
"hot": "pnpm web & sleep 3 && HOTRELOAD=yes pnpm start"
|
||||
},
|
||||
"author": "Mateusz Pstrucha",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.5",
|
||||
"@babel/preset-env": "^7.18.2",
|
||||
"@babel/preset-react": "^7.17.12",
|
||||
"@babel/preset-typescript": "^7.17.12",
|
||||
"babel-loader": "^8.2.5",
|
||||
"electron": "^19.0.6",
|
||||
"electron-builder": "^23.1.0",
|
||||
"electron-packager": "^15.5.1",
|
||||
"electron-rebuild": "^3.2.7",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"ts-loader": "^9.3.1",
|
||||
"webpack": "^5.73.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-dev-server": "^4.9.2"
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.3",
|
||||
"@babel/preset-react": "^7.24.7",
|
||||
"@babel/preset-typescript": "^7.24.7",
|
||||
"babel-loader": "^9.1.3",
|
||||
"electron": "^31.3.1",
|
||||
"electron-builder": "^24.13.3",
|
||||
"html-webpack-plugin": "^5.6.0",
|
||||
"ts-loader": "^9.5.1",
|
||||
"webpack": "^5.93.0",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^5.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/react": "^18.0.14",
|
||||
"@types/react-dom": "^18.0.5",
|
||||
"chart.js": "^3.8.0",
|
||||
"css-loader": "^6.7.1",
|
||||
"date-fns": "^2.28.0",
|
||||
"@electron/rebuild": "^3.6.0",
|
||||
"@emotion/css": "^11.13.0",
|
||||
"@emotion/react": "^11.13.0",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
"@mui/icons-material": "^5.16.7",
|
||||
"@mui/material": "^5.16.7",
|
||||
"@types/adm-zip": "^0.5.5",
|
||||
"@types/better-sqlite3": "^7.6.11",
|
||||
"@types/react": "^18.3.3",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@types/sqlite3": "^3.1.11",
|
||||
"@types/yauzl": "^2.10.3",
|
||||
"adm-zip": "^0.5.15",
|
||||
"better-sqlite3": "^11.1.2",
|
||||
"chart.js": "^4.4.3",
|
||||
"css-loader": "^7.1.2",
|
||||
"date-fns": "^3.6.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"fuse.js": "^6.6.2",
|
||||
"fuse.js": "^7.0.0",
|
||||
"jszip": "^3.10.1",
|
||||
"node-loader": "^2.0.0",
|
||||
"node-stream-zip": "^1.15.0",
|
||||
"node-zip": "^1.1.1",
|
||||
"react": "^18.2.0",
|
||||
"react-chartjs-2": "^4.2.0",
|
||||
"react-date-range": "^1.4.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"sass": "^1.53.0",
|
||||
"sass-loader": "^13.0.2",
|
||||
"sqlite3": "^5.0.8",
|
||||
"style-loader": "^3.3.1",
|
||||
"typescript": "^4.7.4",
|
||||
"utf8": "^3.0.0"
|
||||
"prebuild-install": "^7.1.2",
|
||||
"react": "^18.3.1",
|
||||
"react-chartjs-2": "^5.2.0",
|
||||
"react-date-range": "^2.0.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"sass": "^1.77.8",
|
||||
"sass-loader": "^16.0.0",
|
||||
"style-loader": "^4.0.0",
|
||||
"typescript": "^5.5.4",
|
||||
"utf8": "^3.0.0",
|
||||
"yauzl": "^3.1.3"
|
||||
}
|
||||
}
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
import sqlite, { Database } from 'better-sqlite3'
|
||||
import fs from 'fs'
|
||||
|
||||
import { EntryTypes, FileType, Progress } from './zips'
|
||||
import Inbox from './Inbox'
|
||||
import Message from './Message'
|
||||
|
||||
import RawTakeout from './types/takeout_schema'
|
||||
import { createMediaId, createMessageId } from './normalizers'
|
||||
import { DbError } from './Erros'
|
||||
|
||||
type ConversationFileTypes = 'audio_files' | 'files' | 'gifs' | 'photos' | 'videos' | 'json'
|
||||
|
||||
let sql: { [key: string]: string } = {}
|
||||
|
||||
fs.readdirSync('./ts/sql').forEach(
|
||||
file => (sql[file.split('.')[0]] = fs.readFileSync(`./ts/sql/${file}`).toString())
|
||||
)
|
||||
|
||||
let database: Database
|
||||
|
||||
function connectDB(path: string): Database {
|
||||
let exists = fs.existsSync(path)
|
||||
|
||||
// connect to the database
|
||||
database = sqlite(path)
|
||||
|
||||
if (exists) {
|
||||
// TODO: verify the schema
|
||||
} else {
|
||||
database.exec(sql.create_tables)
|
||||
database.pragma('journal_mode = WAL')
|
||||
}
|
||||
|
||||
return database
|
||||
}
|
||||
|
||||
function closeDB() {
|
||||
if (database) database.close()
|
||||
}
|
||||
|
||||
// function identifyConversaionFile(entryName: string): {
|
||||
// mediaType: ConversationFileTypes
|
||||
// fileName: string
|
||||
// } {
|
||||
// let segments = entryName.split('/')
|
||||
|
||||
// if (segments.length == 5)
|
||||
// if (segments[4].endsWith('.json')) return { mediaType: 'json', fileName: segments[4] }
|
||||
|
||||
// let type = segments[4] as ConversationFileTypes
|
||||
|
||||
// if (segments[4] == 'audio') type = 'audio_files'
|
||||
|
||||
// return { mediaType: type, fileName: identifyFileName(entryName) }
|
||||
// }
|
||||
|
||||
function identifyEntryProperties(entryName: string): { fileName: string; inbox: string | null } {
|
||||
let segments = entryName.split('/'),
|
||||
fileName = segments[segments.length - 1],
|
||||
inbox: string | null = null
|
||||
|
||||
if (segments.length > 3) {
|
||||
inbox = segments[3]
|
||||
}
|
||||
|
||||
return { fileName, inbox }
|
||||
}
|
||||
|
||||
// function identifyFileName(entryName: string) {
|
||||
// let segments = entryName.split('/')
|
||||
// return segments[segments.length - 1]
|
||||
// }
|
||||
|
||||
// function identifyInbox(entryName: string) {
|
||||
// return entryName.split('/')[3]
|
||||
// }
|
||||
|
||||
function insertInbox(inbox: Inbox) {
|
||||
{
|
||||
// inbox
|
||||
const stmt = database.prepare(sql.insert_inbox)
|
||||
|
||||
const data = [
|
||||
inbox.id,
|
||||
inbox.category,
|
||||
inbox.title,
|
||||
inbox.thread_path,
|
||||
~~inbox.is_still_participant,
|
||||
JSON.stringify(inbox.image) || null,
|
||||
JSON.stringify(inbox.participants),
|
||||
JSON.stringify(inbox.joinable_mode) || null,
|
||||
JSON.stringify(inbox.magic_words) || null,
|
||||
JSON.stringify(inbox.meta),
|
||||
]
|
||||
|
||||
stmt.run(...data)
|
||||
}
|
||||
{
|
||||
// stats
|
||||
const stmt = database.prepare(sql.insert_stats)
|
||||
|
||||
for (let stat in inbox.stats) {
|
||||
const data = [inbox.id, stat, JSON.stringify(inbox.stats[stat])]
|
||||
|
||||
stmt.run(...data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function insertMessage(inbox: string, message: Message, salt?: number) {
|
||||
try {
|
||||
const stmt = database.prepare(sql.insert_message)
|
||||
|
||||
const data = [
|
||||
createMessageId(inbox, message, salt),
|
||||
inbox,
|
||||
message.sender_name,
|
||||
message.timestamp_ms,
|
||||
message.content,
|
||||
~~message.is_unsent,
|
||||
message.ip || null,
|
||||
message.call_duration || null,
|
||||
message.missed ? ~~message.missed : null,
|
||||
JSON.stringify(message.photos) || null,
|
||||
JSON.stringify(message.gifs) || null,
|
||||
JSON.stringify(message.videos) || null,
|
||||
JSON.stringify(message.audio_files) || null,
|
||||
JSON.stringify(message.files) || null,
|
||||
JSON.stringify(message.sticker) || null,
|
||||
JSON.stringify(message.share) || null,
|
||||
JSON.stringify(message.reactions) || null,
|
||||
]
|
||||
stmt.run(...data)
|
||||
} catch (e) {
|
||||
if (e instanceof sqlite.SqliteError && e.code == 'SQLITE_CONSTRAINT_PRIMARYKEY') {
|
||||
return insertMessage(inbox, message, salt ? salt + 1 : 1)
|
||||
}
|
||||
|
||||
throw new DbError(`Failed to insert message (${inbox} - ${message.timestamp_ms})`)
|
||||
}
|
||||
}
|
||||
|
||||
function insertMedia(
|
||||
mediaType: EntryTypes,
|
||||
fileName: string,
|
||||
inbox: string | null,
|
||||
buffer: Buffer,
|
||||
salt?: number
|
||||
) {
|
||||
try {
|
||||
const stmt = database.prepare(
|
||||
`INSERT INTO ${mediaType} (id, name, inbox, data) VALUES (?, ?, ?, ?)`
|
||||
)
|
||||
|
||||
const data = [
|
||||
createMediaId(
|
||||
{
|
||||
inbox: inbox || '',
|
||||
fileName,
|
||||
},
|
||||
salt
|
||||
),
|
||||
fileName,
|
||||
inbox || null,
|
||||
buffer,
|
||||
]
|
||||
|
||||
stmt.run(...data)
|
||||
} catch (e) {
|
||||
if (e instanceof sqlite.SqliteError && e.code == 'SQLITE_CONSTRAINT_PRIMARYKEY') {
|
||||
return insertMedia(mediaType, fileName, inbox, buffer, salt ? salt + 1 : 1)
|
||||
}
|
||||
|
||||
throw new DbError(`Failed to insert media (${mediaType} - ${fileName})`)
|
||||
}
|
||||
}
|
||||
|
||||
// function insertGeneral(table: 'group_photos' | 'stickers_used', fileName: string, buffer: Buffer) {
|
||||
// try {
|
||||
// const stmt = database.prepare(`INSERT INTO ${table} (name, data) VALUES (?, ?)`)
|
||||
// stmt.run(fileName, buffer)
|
||||
// } catch (e) {
|
||||
// console.error(e)
|
||||
// }
|
||||
// }
|
||||
|
||||
function insertMeta(name: string, meta: string) {
|
||||
try {
|
||||
const stmt = database.prepare(`INSERT INTO meta (name, data) VALUES (?, ?)`)
|
||||
|
||||
const data = [name, meta]
|
||||
|
||||
stmt.run(name, data)
|
||||
} catch (e) {
|
||||
throw new DbError(`Failed to insert meta (${name})`)
|
||||
}
|
||||
}
|
||||
|
||||
function importRawEntry(entryName: string, buffer: Buffer, type: EntryTypes) {
|
||||
const { fileName, inbox } = identifyEntryProperties(entryName)
|
||||
|
||||
if (type == EntryTypes.INBOX_JSON) {
|
||||
return {
|
||||
raw: JSON.parse(buffer.toString()) as RawTakeout,
|
||||
inbox: inbox,
|
||||
}
|
||||
}
|
||||
|
||||
if (type == EntryTypes.META) {
|
||||
insertMeta(fileName, buffer.toString())
|
||||
return
|
||||
}
|
||||
|
||||
if (type == 'non-message') throw new Error('non-message type not implemented')
|
||||
|
||||
insertMedia(type, fileName, inbox, buffer)
|
||||
}
|
||||
|
||||
function importInbox(inbox: Inbox, progress: Progress) {
|
||||
progress(`Saving inbox ${inbox.title}`, 0)
|
||||
insertInbox(inbox)
|
||||
|
||||
const totalMessages = inbox.messages.length
|
||||
|
||||
const scope = Math.floor(totalMessages / 200)
|
||||
|
||||
inbox.messages.forEach((message, i) => {
|
||||
let percent = i / totalMessages
|
||||
if (i % scope == 0) {
|
||||
progress(inbox.title, percent)
|
||||
}
|
||||
insertMessage(inbox.id, message)
|
||||
})
|
||||
}
|
||||
|
||||
function getMedia(type: string, uri: string, inbox?: string) {
|
||||
if (type == 'group_photos' || type == 'stickers_used') {
|
||||
const stmt = database.prepare(`SELECT * FROM ${type} WHERE name = ?`)
|
||||
const row = stmt.get(uri)
|
||||
|
||||
return row
|
||||
} else {
|
||||
const stmt = database.prepare(`SELECT * FROM ${type} WHERE name = ? AND inbox = ?`)
|
||||
const row = stmt.get(uri, inbox)
|
||||
|
||||
return row
|
||||
}
|
||||
}
|
||||
|
||||
function getInboxes() {
|
||||
const stmt = database.prepare(`SELECT id, title, category FROM inboxes`)
|
||||
const rows = stmt.all()
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
function getInbox(id: string) {
|
||||
const stmt = database.prepare(`SELECT * FROM inboxes WHERE id = ?`)
|
||||
const row = stmt.get(id)
|
||||
|
||||
return row
|
||||
}
|
||||
|
||||
function getMessages(id: string, from: number, to: number) {
|
||||
const stmt = database.prepare(
|
||||
`SELECT * FROM messages WHERE inbox = ? AND timestamp_ms BETWEEN ? AND ?`
|
||||
)
|
||||
const rows = stmt.all(id, from, to)
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
function getStats(inbox: string, stat: string) {
|
||||
const stmt = database.prepare(`SELECT content FROM stats WHERE inbox = ? AND name = ?`)
|
||||
const row = stmt.get(inbox, stat)
|
||||
|
||||
return row
|
||||
}
|
||||
|
||||
function checkForExisting(table: string, name: string, inbox: string | null) {
|
||||
const stmt = database.prepare(
|
||||
inbox
|
||||
? `SELECT name FROM ${table} WHERE name = ? AND inbox = ?`
|
||||
: `SELECT name FROM ${table} WHERE name = ?`
|
||||
)
|
||||
|
||||
const row = stmt.get(name, inbox)
|
||||
|
||||
return !!row
|
||||
}
|
||||
|
||||
export { connectDB, closeDB }
|
||||
|
||||
export { importRawEntry, importInbox }
|
||||
|
||||
export { getInboxes, getInbox, getMessages, getMedia, getStats }
|
||||
|
||||
export { identifyEntryProperties, checkForExisting }
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// create a custom error class for 'zip scanning' errors
|
||||
|
||||
export class ZipError extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.name = 'ZipError'
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class DbError extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.name = 'DbError'
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ const statParsers = [
|
||||
export default class Convo {
|
||||
id: string
|
||||
owner: string
|
||||
type: string
|
||||
// type: string
|
||||
category: string
|
||||
members: Member[]
|
||||
|
||||
firstMessage: number
|
||||
@@ -60,7 +61,8 @@ export default class Convo {
|
||||
|
||||
this.id = prim.id
|
||||
this.owner = owner
|
||||
this.type = prim.meta?.type!
|
||||
// this.type = prim.meta?.type!
|
||||
this.category = prim.category
|
||||
|
||||
this.getMember = (name: string) => this.members.find(m => m.name == name)
|
||||
this.getOwner = () => this.getMember(owner)
|
||||
@@ -0,0 +1,110 @@
|
||||
import fs from 'fs'
|
||||
import { join } from 'path'
|
||||
|
||||
import { message, messagesPart, messageWithMedia } from './types/takeout'
|
||||
|
||||
const inboxIdRegex = /_[^\/]*?$/,
|
||||
inboxCatRegex = /\/([^\/])+\/[^\/]+$/,
|
||||
messagePartRegex = /message_\d+\.json/
|
||||
|
||||
const scanDirs = [
|
||||
'archived_threads',
|
||||
'e2ee_cutover',
|
||||
'filtered_threads',
|
||||
'inbox',
|
||||
'message_requests',
|
||||
]
|
||||
|
||||
export var findInboxes = (path: string): Promise<Inbox[]> =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (!fs.existsSync(path)) return reject("Directory doesn't exist")
|
||||
|
||||
const availableDirs = fs.readdirSync(path).filter(d => scanDirs.includes(d))
|
||||
|
||||
const inboxes: Inbox[] = []
|
||||
|
||||
for (let dir of availableDirs) {
|
||||
for (let inbox of fs.readdirSync(join(path, dir))) {
|
||||
inboxes.push(new Inbox(join(path, dir, inbox)))
|
||||
}
|
||||
}
|
||||
|
||||
resolve(inboxes)
|
||||
})
|
||||
|
||||
export default class Inbox {
|
||||
path: string
|
||||
id: string
|
||||
category: string
|
||||
parts: string[]
|
||||
|
||||
messages: message[]
|
||||
meta!: {
|
||||
title: string
|
||||
// type: string
|
||||
participants: string[]
|
||||
participates: boolean
|
||||
image?: { uri: string; created: number }
|
||||
date: number
|
||||
}
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path
|
||||
this.parts = []
|
||||
this.messages = []
|
||||
this.category = 'N/A'
|
||||
this.id = 'N/A'
|
||||
|
||||
let id = inboxIdRegex.exec(path)
|
||||
if (id) this.id = id[0].slice(-10)
|
||||
|
||||
// go over scanDirs, and check if the path contains it
|
||||
for (let dir of scanDirs) {
|
||||
if (path.includes(dir)) {
|
||||
this.category = dir
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.findParts()
|
||||
}
|
||||
|
||||
private findParts() {
|
||||
if (this.parts.length != 0) return this.parts
|
||||
|
||||
const availableParts = fs.readdirSync(this.path).filter(f => f.match(messagePartRegex))
|
||||
|
||||
this.parts.push(
|
||||
...availableParts.filter(p => !this.parts.includes(p)).map(p => join(this.path, p))
|
||||
)
|
||||
return this.parts
|
||||
}
|
||||
|
||||
async loadParts() {
|
||||
if (this.messages.length != 0) return this.messages
|
||||
|
||||
let metas: (typeof this.meta)[] = []
|
||||
|
||||
for (let partPath of this.parts) {
|
||||
let part: messagesPart = JSON.parse(fs.readFileSync(partPath).toString())
|
||||
|
||||
metas.push({
|
||||
title: part.title,
|
||||
// type: part.thread_type,
|
||||
participants: part.participants.map(p => p.name),
|
||||
participates: part.is_still_participant,
|
||||
date: part.messages.at(-1)?.timestamp_ms ?? 0,
|
||||
image: part.image && {
|
||||
uri: part.image.uri,
|
||||
created: part.image.creation_timestamp,
|
||||
},
|
||||
})
|
||||
|
||||
this.messages.push(...part.messages)
|
||||
}
|
||||
|
||||
this.meta = metas.sort(({ date: a }, { date: b }) => a - b)[0]
|
||||
|
||||
return this.messages
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,117 @@
|
||||
import utf8 from 'utf8'
|
||||
import { join } from 'path'
|
||||
import { message, messageMedia, messageWithMedia } from './types/takeout'
|
||||
import { parse } from 'date-fns'
|
||||
|
||||
export default class Message {
|
||||
sender: string
|
||||
time: number
|
||||
content: string
|
||||
|
||||
type?: string
|
||||
unsent?: boolean
|
||||
|
||||
reactions?: {
|
||||
reaction: string
|
||||
actor: string
|
||||
}[]
|
||||
|
||||
media?: {
|
||||
[type: string]: messageMedia[]
|
||||
}
|
||||
|
||||
share?: {
|
||||
link?: string
|
||||
share_text?: string
|
||||
}
|
||||
|
||||
sticker?: string
|
||||
|
||||
call?: {
|
||||
duration?: number
|
||||
missed?: boolean
|
||||
}
|
||||
|
||||
takenDown?: boolean
|
||||
|
||||
constructor(raw: message, sourceInboxPath: string) {
|
||||
let rootInboxesPath = '/' + sourceInboxPath.split('/').slice(0, -2).join('/')
|
||||
|
||||
this.sender = utf8.decode(raw.sender_name)
|
||||
this.time = raw.timestamp_ms
|
||||
this.content = utf8.decode(raw.content ?? '')
|
||||
|
||||
raw.is_unsent && (this.unsent = raw.is_unsent)
|
||||
raw.type != 'Generic' && (this.type = raw.type)
|
||||
raw.share && (this.share = raw.share)
|
||||
raw.sticker &&
|
||||
(this.sticker = join(rootInboxesPath, raw.sticker.uri.split('/').slice(1).join('/')))
|
||||
|
||||
raw.is_taken_down && (this.takenDown = raw.is_taken_down)
|
||||
|
||||
raw.reactions &&
|
||||
(this.reactions = raw.reactions.map(r => ({
|
||||
actor: utf8.decode(r.actor),
|
||||
reaction: utf8.decode(r.reaction),
|
||||
})))
|
||||
|
||||
// NOTICE: ignoring raw.ip
|
||||
|
||||
var parseMediaPath = ({ uri, creation_timestamp }) => ({
|
||||
// "messages/inbox/ewaborrutos_iboltosofa/photos/277082391_1752607051744282_8714558476873703522_n_1752607048410949.jpg"
|
||||
// "your_facebook_activity/messages/e2ee_cutover/nicoladyba_3500463636883274/photos/369261279_3155584381402981_5846344907408322016_n_3155584378069648.jpg"
|
||||
// uri: join(sourceInboxPath, uri.split('/').slice(3).join('/')),
|
||||
uri: join(rootInboxesPath, uri.split('/').slice(-4).join('/')),
|
||||
creation_timestamp,
|
||||
})
|
||||
|
||||
// var parseMediaPath = ({ uri, creation_timestamp }) => {
|
||||
// console.log([
|
||||
// uri,
|
||||
// sourceInboxPath,
|
||||
// sourceInboxPath.split('/'),
|
||||
// uri.split(sourceInboxPath.split('/').at(-1)),
|
||||
// ])
|
||||
// return parseMediaPath1({ uri, creation_timestamp })
|
||||
// }
|
||||
|
||||
// media
|
||||
if (raw.photos || raw.audio_files || raw.files || raw.gifs || raw.videos) {
|
||||
this.media = {}
|
||||
|
||||
raw.photos && (this.media.photos = raw.photos.map(parseMediaPath))
|
||||
raw.audio_files && (this.media.audios = raw.audio_files.map(parseMediaPath))
|
||||
raw.files && (this.media.files = raw.files.map(parseMediaPath))
|
||||
raw.gifs && (this.media.gifs = raw.gifs.map(parseMediaPath))
|
||||
raw.videos && (this.media.videos = raw.videos.map(parseMediaPath))
|
||||
}
|
||||
|
||||
if (raw.call_duration || raw.missed || raw.type == 'Call') {
|
||||
this.call = {
|
||||
duration: raw.call_duration,
|
||||
missed: raw.missed,
|
||||
}
|
||||
}
|
||||
|
||||
this.extendTime()
|
||||
}
|
||||
|
||||
extendTime() {
|
||||
let stringTime = this.time.toString()
|
||||
|
||||
if (stringTime.length != 13) return
|
||||
|
||||
let total = 0
|
||||
|
||||
// sum all character codes
|
||||
for (let c = 0; c < this.content.length; c++) total += this.content.charCodeAt(c)
|
||||
|
||||
// limit to 3 digits
|
||||
total %= 1000
|
||||
|
||||
// append to end of current timestamp
|
||||
stringTime += total.toString().padStart(3, '0')
|
||||
|
||||
this.time = parseInt(stringTime)
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -2,6 +2,8 @@ import utf8 from 'utf8'
|
||||
import Convo from './Convo'
|
||||
import Inbox, { findInboxes } from './Inbox'
|
||||
|
||||
import fs from 'fs'
|
||||
|
||||
function counter(n: number) {
|
||||
return [n, 1]
|
||||
}
|
||||
@@ -43,7 +45,7 @@ export async function scan(
|
||||
let owner = utf8.decode(
|
||||
Object.entries(
|
||||
inboxes
|
||||
.filter(i => i.meta?.type == 'Regular') // ignore groups
|
||||
// .filter(i => i.meta?.type == 'Regular') // ignore groups
|
||||
.reduce((sum, { meta }) => {
|
||||
// count participant occurrences
|
||||
meta!.participants.forEach(p =>
|
||||
@@ -105,7 +107,10 @@ export async function scan(
|
||||
contact('main', 'Finished', 4)
|
||||
contact('sub', 'All tasks ok', 100)
|
||||
|
||||
console.info('scan: ', Convos)
|
||||
console.info('scan: ', convos)
|
||||
|
||||
// dump convos to json file
|
||||
fs.writeFileSync('./convos.json', JSON.stringify(convos, null, 2), 'utf-8')
|
||||
|
||||
convos.forEach(c => (Convos[c.id] = c)) // rearrange to global exported object
|
||||
|
||||
@@ -6,19 +6,19 @@ export type unescapedString = string
|
||||
export type messagesPart = {
|
||||
title: unescapedString
|
||||
thread_path: string
|
||||
thread_type: string
|
||||
participants: { name: unescapedString }[]
|
||||
magic_words: []
|
||||
messages: (message & messageWithMedia)[]
|
||||
image?: {
|
||||
uri: string
|
||||
creation_timestamp: timestampSeconds
|
||||
}
|
||||
is_still_participant: boolean
|
||||
magic_words: []
|
||||
joinable_mode: {
|
||||
mode: number
|
||||
link: string
|
||||
}
|
||||
image?: {
|
||||
uri: string
|
||||
creation_timestamp: timestampSeconds
|
||||
}
|
||||
|
||||
participants: { name: unescapedString }[]
|
||||
messages: message[]
|
||||
}
|
||||
|
||||
export type message = {
|
||||
@@ -50,6 +50,12 @@ export type message = {
|
||||
sticker?: {
|
||||
uri: string
|
||||
}
|
||||
|
||||
photos?: messageMedia[]
|
||||
audio_files?: messageMedia[]
|
||||
files?: messageMedia[]
|
||||
gifs?: (messageMedia & { creation_timestamp: never })[]
|
||||
videos?: (messageMedia & { thumbnail: { uri: string } })[]
|
||||
}
|
||||
|
||||
export type messageWithMedia = {
|
||||
@@ -0,0 +1,6 @@
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
export const eProgress = new EventEmitter()
|
||||
export enum E_PROGRESS {
|
||||
PROGRESS_ZIP = 'progress-zip',
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import crypto from 'crypto'
|
||||
import Message from './Message'
|
||||
|
||||
export function pathOriginalToShort(path: string): string {
|
||||
if (path.startsWith('http')) return path
|
||||
if (!path.startsWith('your_facebook_activity')) throw new Error('Invalid path ' + path)
|
||||
|
||||
let segments = path.split('/')
|
||||
|
||||
return segments.slice(2).join('/')
|
||||
}
|
||||
|
||||
export function pathShortToOriginal(path: string): string {
|
||||
return `your_facebook_activity/messages/${path}`
|
||||
}
|
||||
|
||||
export function pathOriginalToName(path: string): string {
|
||||
let segments = path.split('/')
|
||||
return segments[segments.length - 1]
|
||||
}
|
||||
|
||||
export function timestampSecToMs(timestamp: number): number {
|
||||
return timestamp * 1000
|
||||
}
|
||||
|
||||
export function timestampMsToSec(timestamp: number): number {
|
||||
return Math.floor(timestamp / 1000)
|
||||
}
|
||||
|
||||
export function createMessageId(
|
||||
inbox: string,
|
||||
{ sender_name, timestamp_ms, content }: Message,
|
||||
salt?: number
|
||||
): string {
|
||||
let hash = crypto
|
||||
.createHash('sha1')
|
||||
.update(inbox + sender_name + timestamp_ms)
|
||||
.digest('hex')
|
||||
|
||||
if (salt) {
|
||||
hash += '_' + salt
|
||||
}
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
export function createMediaId({ inbox, fileName }, salt?: number): string {
|
||||
let hash = crypto
|
||||
.createHash('sha1')
|
||||
.update(inbox + fileName)
|
||||
.digest('hex')
|
||||
|
||||
if (salt) {
|
||||
hash += '_' + salt
|
||||
}
|
||||
|
||||
return hash
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
CREATE TABLE
|
||||
inboxes (
|
||||
id TEXT NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
thread_path TEXT NOT NULL,
|
||||
is_still_participant BOOLEAN NOT NULL,
|
||||
-- JSON
|
||||
image TEXT,
|
||||
participants TEXT NOT NULL,
|
||||
joinable_mode TEXT,
|
||||
magic_words TEXT,
|
||||
meta TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
messages (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT NOT NULL,
|
||||
sender_name TEXT NOT NULL,
|
||||
timestamp_ms INTEGER NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
is_unsent BOOLEAN NOT NULL,
|
||||
-- optional
|
||||
ip TEXT,
|
||||
call_duration INTEGER,
|
||||
missed BOOLEAN,
|
||||
-- JSON
|
||||
photos TEXT,
|
||||
gifs TEXT,
|
||||
videos TEXT,
|
||||
audio_files TEXT,
|
||||
files TEXT,
|
||||
sticker TEXT,
|
||||
share TEXT,
|
||||
reactions TEXT
|
||||
);
|
||||
|
||||
-- META
|
||||
CREATE TABLE
|
||||
stats (
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
meta (
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- MEDIA TABLES
|
||||
CREATE TABLE
|
||||
group_photos (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
stickers_used (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
photos (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
videos (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
audio_files (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
files (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
gifs (
|
||||
id TEXT PRIMARY KEY,
|
||||
inbox TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,15 @@
|
||||
INSERT
|
||||
OR IGNORE INTO inboxes (
|
||||
id,
|
||||
category,
|
||||
title,
|
||||
thread_path,
|
||||
is_still_participant,
|
||||
image,
|
||||
participants,
|
||||
joinable_mode,
|
||||
magic_words,
|
||||
meta
|
||||
)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
@@ -0,0 +1,4 @@
|
||||
INSERT INTO
|
||||
? (name, inbox, data)
|
||||
VALUES
|
||||
(?, ?, ?)
|
||||
@@ -0,0 +1,40 @@
|
||||
INSERT INTO
|
||||
messages (
|
||||
id,
|
||||
inbox,
|
||||
sender_name,
|
||||
timestamp_ms,
|
||||
content,
|
||||
is_unsent,
|
||||
ip,
|
||||
call_duration,
|
||||
missed,
|
||||
photos,
|
||||
gifs,
|
||||
videos,
|
||||
audio_files,
|
||||
files,
|
||||
sticker,
|
||||
share,
|
||||
reactions
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
);
|
||||
@@ -0,0 +1,4 @@
|
||||
INSERT INTO
|
||||
stats (inbox, name, content)
|
||||
VALUES
|
||||
(?, ?, ?);
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Member } from '../Inbox'
|
||||
import Message from '../Message'
|
||||
|
||||
export interface StatParser {
|
||||
id: string
|
||||
|
||||
results: any
|
||||
|
||||
every(message: Message): void
|
||||
}
|
||||
|
||||
export function prepPerMember(members: Member[], initial: () => any) {
|
||||
let out: {
|
||||
[memberName: string]: ReturnType<typeof initial>
|
||||
} = {}
|
||||
|
||||
for (let { name } of members) {
|
||||
out[name] = initial()
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
+24
-30
@@ -1,36 +1,30 @@
|
||||
import { prepStatResults, statParser } from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
// import { prepStatResults, statParser } from '../types/Stat'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'photosPerMember',
|
||||
export default class MediaPerMember implements StatParser {
|
||||
id = 'mediaPerMember'
|
||||
results
|
||||
|
||||
begin: ({ members }) =>
|
||||
prepStatResults(members, () => ({
|
||||
constructor(inbox: Inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => ({
|
||||
photos: 0,
|
||||
videos: 0,
|
||||
audios: 0,
|
||||
files: 0,
|
||||
gifs: 0,
|
||||
videos: 0,
|
||||
audio_files: 0,
|
||||
files: 0,
|
||||
stickers: 0,
|
||||
})),
|
||||
}))
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
if ('sticker' in message) prev[member.name].stickers += 1
|
||||
|
||||
// FIXME: this probably can be done in 3 lines but i can't be bothered right now
|
||||
if (message.media) {
|
||||
if ('photos' in message.media)
|
||||
prev[member.name].photos += message.media.photos.length
|
||||
if ('videos' in message.media)
|
||||
prev[member.name].videos += message.media.videos.length
|
||||
if ('audios' in message.media)
|
||||
prev[member.name].audios += message.media.audios.length
|
||||
if ('files' in message.media)
|
||||
prev[member.name].files += message.media.files.length
|
||||
if ('gifs' in message.media)
|
||||
prev[member.name].gifs += message.media.gifs.length
|
||||
}
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => prev,
|
||||
} as statParser
|
||||
every(message: Message) {
|
||||
let sender = message.sender_name
|
||||
if (message.photos) this.results[sender].photos += message.photos.length
|
||||
if (message.gifs) this.results[sender].gifs += message.gifs.length
|
||||
if (message.videos) this.results[sender].videos += message.videos.length
|
||||
if (message.audio_files) this.results[sender].audio_files += message.audio_files.length
|
||||
if (message.files) this.results[sender].files += message.files.length
|
||||
if (message.sticker) this.results[sender].stickers += 1
|
||||
}
|
||||
}
|
||||
+32
-17
@@ -1,13 +1,32 @@
|
||||
import { monthsEmpty, prepStatResults, statParser } from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'messagesPerDay',
|
||||
const monthsEmpty = (): 0[][] => [
|
||||
new Array(31).fill(0),
|
||||
new Array(29).fill(0), // FIXME: this will cause problems
|
||||
new Array(31).fill(0),
|
||||
new Array(30).fill(0),
|
||||
new Array(31).fill(0),
|
||||
new Array(30).fill(0),
|
||||
new Array(31).fill(0),
|
||||
new Array(31).fill(0),
|
||||
new Array(30).fill(0),
|
||||
new Array(31).fill(0),
|
||||
new Array(30).fill(0),
|
||||
new Array(31).fill(0),
|
||||
]
|
||||
|
||||
begin: ({ firstMessage, lastMessage, members }) => {
|
||||
let firstYear = new Date(firstMessage / 1e3).getFullYear(),
|
||||
lastYear = new Date(lastMessage / 1e3).getFullYear()
|
||||
export default class messagesPerDay implements StatParser {
|
||||
id = 'messagesPerDay'
|
||||
results
|
||||
|
||||
return prepStatResults(members, () => {
|
||||
constructor(inbox: Inbox) {
|
||||
let firstYear = new Date(inbox.meta.firstMessage).getFullYear(),
|
||||
lastYear = new Date(inbox.meta.lastMessage).getFullYear()
|
||||
// FIXME: dynamic year range
|
||||
|
||||
this.results = prepPerMember(inbox.participants, () => {
|
||||
let prep: {
|
||||
[year: string]: number[][]
|
||||
} = {}
|
||||
@@ -16,18 +35,14 @@ export default {
|
||||
}
|
||||
return prep
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
let date = new Date(message.time / 1e3),
|
||||
every(message: Message) {
|
||||
let date = new Date(message.timestamp_ms),
|
||||
y = date.getFullYear(),
|
||||
m = date.getMonth(),
|
||||
d = date.getDate()
|
||||
|
||||
prev[member.name][y][m][d - 1] += 1
|
||||
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => prev,
|
||||
} as statParser
|
||||
this.results[message.sender_name][y][m][d - 1] += 1
|
||||
}
|
||||
}
|
||||
+13
-11
@@ -1,14 +1,16 @@
|
||||
import { prepStatResults, statParser } from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'messagesPerHour',
|
||||
export default class messagesPerHour implements StatParser {
|
||||
id = 'messagesPerHour'
|
||||
results
|
||||
|
||||
begin: ({ members }) => prepStatResults(members, () => Array(24).fill(0)),
|
||||
constructor(inbox: Inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => Array(24).fill(0))
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev, other) => {
|
||||
prev[member.name][new Date(message.time / 1e3).getHours()] += 1
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev, other) => prev,
|
||||
} as statParser
|
||||
every(message: Message) {
|
||||
this.results[message.sender_name][new Date(message.timestamp_ms / 1e3).getHours()] += 1
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import { prepStatResults, statParser } from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'messagesPerMember',
|
||||
export default class messagesPerMember implements StatParser {
|
||||
id = 'messagesPerMember'
|
||||
results
|
||||
|
||||
begin: ({ members }) => prepStatResults(members, () => 0),
|
||||
constructor(inbox: Inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => 0)
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
prev[member.name] += 1
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => prev,
|
||||
} as statParser
|
||||
every(message: Message) {
|
||||
this.results[message.sender_name] += 1
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
import { prepStatResults, statParser } from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'messagesPerWeekday',
|
||||
export default class messagesPerWeekday implements StatParser {
|
||||
id = 'messagesPerWeekday'
|
||||
results
|
||||
|
||||
begin: ({ members }) =>
|
||||
prepStatResults(members, () => [0, 0, 0, 0, 0, 0, 0]),
|
||||
constructor(inbox: Inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => new Array(7).fill(0))
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
prev[member.name][new Date(message.time / 1e3).getDay()] += 1
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => prev,
|
||||
} as statParser
|
||||
every(message: Message) {
|
||||
this.results[message.sender_name][new Date(message.timestamp_ms).getDay()] += 1
|
||||
}
|
||||
}
|
||||
+15
-21
@@ -1,32 +1,26 @@
|
||||
import {
|
||||
prepStatResults,
|
||||
sortObjectbyValueNumber,
|
||||
statParser,
|
||||
} from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
const emojiPattern =
|
||||
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g
|
||||
|
||||
export default {
|
||||
id: 'mostUsedEmoji',
|
||||
export default class mostUsedEmoji implements StatParser {
|
||||
id = 'mostUsedEmoji'
|
||||
results
|
||||
|
||||
begin: ({ members }) => prepStatResults(members, () => ({})),
|
||||
constructor(inbox: Inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => ({}))
|
||||
}
|
||||
|
||||
every(message: Message) {
|
||||
let sender = message.sender_name
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
if (message.content.length > 0) {
|
||||
let emojis = message.content.match(emojiPattern)
|
||||
if (emojis) {
|
||||
emojis.forEach(
|
||||
e => (prev[member.name][e] = (prev[member.name][e] + 1) | 1)
|
||||
)
|
||||
emojis.forEach(e => (this.results[sender][e] = (this.results[sender][e] + 1) | 1))
|
||||
}
|
||||
}
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => {
|
||||
for (let name in prev) prev[name] = sortObjectbyValueNumber(prev[name])
|
||||
|
||||
return prev
|
||||
},
|
||||
} as statParser
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,23 @@
|
||||
import {
|
||||
prepStatResults,
|
||||
sortObjectbyValueNumber,
|
||||
statParser,
|
||||
} from '../types/Stat'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'mostUsedReactions',
|
||||
export default class mostUsedReactions implements StatParser {
|
||||
id = 'mostUsedReactions'
|
||||
results
|
||||
|
||||
begin: ({ members }) =>
|
||||
prepStatResults(members, () => ({ got: {}, used: {} })),
|
||||
constructor(inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => ({ got: {}, used: {} }))
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
every(message: Message) {
|
||||
if (message.reactions) {
|
||||
for (let { reaction, actor } of message.reactions) {
|
||||
const got = prev[member.name].got,
|
||||
used = prev[actor].used
|
||||
const got = this.results[message.sender_name].got,
|
||||
used = this.results[actor].used
|
||||
|
||||
got[reaction] = got[reaction] + 1 || 1
|
||||
used[reaction] = used[reaction] + 1 || 1
|
||||
}
|
||||
}
|
||||
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => {
|
||||
for (let { name } of convo.members) {
|
||||
prev[name].got = sortObjectbyValueNumber(prev[name].got)
|
||||
prev[name].used = sortObjectbyValueNumber(prev[name].used)
|
||||
}
|
||||
return prev
|
||||
},
|
||||
} as statParser
|
||||
}
|
||||
}
|
||||
+17
-21
@@ -1,26 +1,22 @@
|
||||
import {
|
||||
prepStatResults,
|
||||
sortObjectbyValueNumber,
|
||||
statParser,
|
||||
} from '../types/Stat'
|
||||
import Inbox from '../Inbox'
|
||||
import Message from '../Message'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'mostUsedWords',
|
||||
export default class mostUsedWords implements StatParser {
|
||||
id = 'mostUsedWords'
|
||||
results
|
||||
|
||||
begin: ({ members }) => prepStatResults(members, () => ({})),
|
||||
constructor(inbox: Inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => ({}))
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
if (message.content.length > 0)
|
||||
every(message: Message) {
|
||||
if (message.content.length > 0) {
|
||||
let sender = message.sender_name
|
||||
message.content.split(' ').forEach(word => {
|
||||
if (prev[member.name][word]) prev[member.name][word] += 1
|
||||
else prev[member.name][word] = 1
|
||||
if (this.results[sender][word]) this.results[sender][word] += 1
|
||||
else this.results[sender][word] = 1
|
||||
})
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => {
|
||||
for (let name in prev) prev[name] = sortObjectbyValueNumber(prev[name])
|
||||
|
||||
return prev
|
||||
},
|
||||
} as statParser
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -1,15 +1,15 @@
|
||||
import { prepStatResults, statParser } from '../types/Stat'
|
||||
import { prepPerMember, StatParser } from './StatParser'
|
||||
|
||||
export default {
|
||||
id: 'wordsPerMember',
|
||||
export default class wordsPerMember implements StatParser {
|
||||
id = 'wordsPerMember'
|
||||
results
|
||||
|
||||
begin: ({ members }) => prepStatResults(members, () => 0),
|
||||
constructor(inbox) {
|
||||
this.results = prepPerMember(inbox.participants, () => 0)
|
||||
}
|
||||
|
||||
every: (message, member, convo, prev) => {
|
||||
every(message) {
|
||||
if (message.content.length > 0)
|
||||
prev[member.name] += message.content.split(' ').length
|
||||
return prev
|
||||
},
|
||||
|
||||
end: (convo, prev) => prev,
|
||||
} as statParser
|
||||
this.results[message.sender_name] += message.content.split(' ').length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export enum MAIN_TO_RENDERER {
|
||||
UPDATE_PROGRESS = 'update-progress',
|
||||
}
|
||||
|
||||
export enum RENDERER_TO_MAIN {
|
||||
// pre import
|
||||
GET_ZIP_PATHS = 'get-zip-paths',
|
||||
GET_DB_PATH = 'get-db-path',
|
||||
// import
|
||||
IMPORT_ZIPS = 'import-zips',
|
||||
IMPORT_DB = 'import-db',
|
||||
// queries
|
||||
GET_INBOXES = 'get-inboxes',
|
||||
GET_INBOX = 'get-inbox',
|
||||
GET_MESSAGES = 'get-messages',
|
||||
GET_MEDIA = 'get-media',
|
||||
GET_STATS = 'get-stats',
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Facebook takeout message metadata
|
||||
*/
|
||||
export default interface RawTakeout {
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
participants: [
|
||||
{
|
||||
name: string
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
name: string
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
messages: [
|
||||
{
|
||||
sender_name: string
|
||||
timestamp_ms: number
|
||||
content?: string
|
||||
is_unsent?: boolean
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
photos?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
gifs?: [
|
||||
{
|
||||
uri: string
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
reactions?: [
|
||||
{
|
||||
reaction: string
|
||||
actor: string
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
reaction: string
|
||||
actor: string
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
share?: {
|
||||
link: string
|
||||
share_text: string
|
||||
[k: string]: unknown
|
||||
}
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
videos?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
audio_files?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
files?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
sticker?: {
|
||||
uri: string
|
||||
ai_stickers: {
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
[k: string]: unknown
|
||||
}
|
||||
ip?: string
|
||||
call_duration?: number
|
||||
missed?: boolean
|
||||
is_geoblocked_for_viewer: boolean
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
sender_name: string
|
||||
timestamp_ms: number
|
||||
content?: string
|
||||
is_unsent?: boolean
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
photos?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
gifs?: [
|
||||
{
|
||||
uri: string
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
reactions?: [
|
||||
{
|
||||
reaction: string
|
||||
actor: string
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
reaction: string
|
||||
actor: string
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
share?: {
|
||||
link: string
|
||||
share_text: string
|
||||
[k: string]: unknown
|
||||
}
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
videos?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
audio_files?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
/**
|
||||
* @minItems 1
|
||||
*/
|
||||
files?: [
|
||||
{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
},
|
||||
...{
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
type?: string
|
||||
sticker?: {
|
||||
uri: string
|
||||
ai_stickers: {
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
[k: string]: unknown
|
||||
}
|
||||
ip?: string
|
||||
call_duration?: number
|
||||
missed?: boolean
|
||||
is_geoblocked_for_viewer: boolean
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
]
|
||||
title: string
|
||||
is_still_participant: boolean
|
||||
thread_path: string
|
||||
magic_words: {
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
image?: {
|
||||
uri: string
|
||||
creation_timestamp: number
|
||||
[k: string]: unknown
|
||||
}
|
||||
joinable_mode: {
|
||||
mode: number
|
||||
link: string
|
||||
[k: string]: unknown
|
||||
}
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
export type RawTakeoutMessage = RawTakeout['messages'][0]
|
||||
+346
@@ -0,0 +1,346 @@
|
||||
import StreamZip, { ZipEntry } from 'node-stream-zip'
|
||||
|
||||
import { ZipError } from './Erros'
|
||||
import { E_PROGRESS, eProgress } from './emmiters'
|
||||
import { checkForExisting, identifyEntryProperties } from './Database'
|
||||
|
||||
type DupeDb = {
|
||||
entries: { [entryName: string]: [number, string] }
|
||||
multiple: { [entryName: string]: string[] }
|
||||
}
|
||||
type Indexed = { [entryName: string]: string | string[] }
|
||||
type Handler = (entryName: string, blob: Buffer, type: EntryTypes) => Promise<void>
|
||||
export type Progress = (title: string, percent: number) => void
|
||||
|
||||
export type FileType = 'conversation' | 'group_photos' | 'stickers_used' | 'meta' | 'non-message'
|
||||
|
||||
export enum EntryTypes {
|
||||
GROUP_PHOTOS = 'group_photos',
|
||||
STICKERS_USED = 'stickers_used',
|
||||
META = 'meta',
|
||||
NON_MESSAGE = 'non-message',
|
||||
INBOX_JSON = 'inbox_json',
|
||||
INBOX_PHOTOS = 'photos',
|
||||
INBOX_VIDEOS = 'videos',
|
||||
INBOX_AUDIO = 'audio_files',
|
||||
INBOX_FILES = 'files',
|
||||
INBOX_GIFS = 'gifs',
|
||||
}
|
||||
|
||||
enum StreamCodes {
|
||||
STREAM_INVALID,
|
||||
STREAM_SKIPPED,
|
||||
STREAM_HANDLED,
|
||||
}
|
||||
|
||||
const knownDirs = {
|
||||
conversations: [
|
||||
'inbox',
|
||||
'e2ee_cutover',
|
||||
'archived_threads',
|
||||
'filtered_threads',
|
||||
'message_requests',
|
||||
],
|
||||
meta: [
|
||||
'autofill_information.json',
|
||||
'community_chats_settings.json',
|
||||
"messenger_contacts_you've_blocked.json",
|
||||
'secret_conversations.json',
|
||||
'support_messages.json',
|
||||
'your_chat_settings_on_web.json',
|
||||
'your_cross-app_messaging_settings.json',
|
||||
],
|
||||
}
|
||||
|
||||
function duplicateCheck(entry: ZipEntry, zipPath: string, dupeDb: DupeDb) {
|
||||
let crc = entry.crc,
|
||||
existing = dupeDb.entries[entry.name]
|
||||
|
||||
if (existing) {
|
||||
let [existingCrc, existingZipPath] = existing
|
||||
|
||||
if (existingCrc != crc) {
|
||||
// existing is invalid, replace it
|
||||
if (existingCrc == 0) {
|
||||
existing[0] = crc
|
||||
existing[1] = zipPath
|
||||
return 'replaced-invalid-duplicate'
|
||||
}
|
||||
|
||||
// new entry is invalid, ignore it
|
||||
if (crc == 0) return 'ignored-invalid-duplicate'
|
||||
|
||||
if (!dupeDb.multiple[entry.name]) {
|
||||
dupeDb.multiple[entry.name] = [zipPath]
|
||||
} else {
|
||||
dupeDb.multiple[entry.name].push(zipPath)
|
||||
}
|
||||
return 'mismatched-duplicate-error'
|
||||
}
|
||||
|
||||
// matching crcs, don't do anything
|
||||
if (existingCrc == crc) {
|
||||
return 'ignored-duplicate'
|
||||
}
|
||||
}
|
||||
|
||||
dupeDb.entries[entry.name] = [crc, zipPath]
|
||||
return 'added-new-entry'
|
||||
}
|
||||
|
||||
// function identifyFile(filepath: string) {
|
||||
// let segments = filepath.split('/')
|
||||
|
||||
// // all zips should have only one directory at the top level
|
||||
// // if after skipping directories, there is only one segment, then something is wrong
|
||||
// if (segments.length < 2) {
|
||||
// throw new ZipError(`Invalid zip structure: '${filepath}'`)
|
||||
// }
|
||||
|
||||
// if (segments[1] != 'messages') return 'non-message'
|
||||
|
||||
// if (segments[2] == 'photos') return 'group_photos'
|
||||
// if (segments[2] == 'stickers_used') return 'stickers_used'
|
||||
// if (knownDirs.conversations.includes(segments[2])) return 'conversation'
|
||||
// if (knownDirs.meta.includes(segments[2])) return 'meta'
|
||||
|
||||
// throw new ZipError(`Unknown zip entry: '${filepath}'`)
|
||||
// }
|
||||
|
||||
function identifyEntry(entryName: string) {
|
||||
let segments = entryName.split('/')
|
||||
|
||||
// console.log(segments)
|
||||
|
||||
if (segments.length < 2) {
|
||||
throw new ZipError(`Invalid zip structure: '${entryName}'`)
|
||||
}
|
||||
|
||||
if (segments[1] != 'messages') return EntryTypes.NON_MESSAGE
|
||||
|
||||
if (segments[2] == 'photos') return EntryTypes.INBOX_PHOTOS
|
||||
if (segments[2] == 'stickers_used') return EntryTypes.STICKERS_USED
|
||||
|
||||
if (knownDirs.conversations.includes(segments[2])) {
|
||||
let category = segments[4]
|
||||
|
||||
if (category == 'photos') return EntryTypes.INBOX_PHOTOS
|
||||
if (category == 'videos') return EntryTypes.INBOX_VIDEOS
|
||||
if (category == 'audio') return EntryTypes.INBOX_AUDIO
|
||||
if (category == 'files') return EntryTypes.INBOX_FILES
|
||||
if (category == 'gifs') return EntryTypes.INBOX_GIFS
|
||||
if (category.endsWith('.json')) return EntryTypes.INBOX_JSON
|
||||
}
|
||||
if (knownDirs.meta.includes(segments[2])) return EntryTypes.META
|
||||
|
||||
throw new ZipError(`Unknown zip entry: '${entryName}'`)
|
||||
}
|
||||
|
||||
function parseRawEntry(entry: ZipEntry, zipPath: string, dupeDb: DupeDb) {
|
||||
// ignore directories
|
||||
if (entry.isDirectory == true) return
|
||||
|
||||
// const fileType = identifyFile(entry.name)
|
||||
const fileType = identifyEntry(entry.name)
|
||||
|
||||
// ignore non-message files
|
||||
if (fileType == EntryTypes.NON_MESSAGE) return
|
||||
|
||||
duplicateCheck(entry, zipPath, dupeDb)
|
||||
}
|
||||
|
||||
function scanZips(filepaths: string[]) {
|
||||
let scanPromises: Promise<void>[] = []
|
||||
|
||||
var dupeDb: DupeDb = {
|
||||
entries: {},
|
||||
multiple: {},
|
||||
}
|
||||
|
||||
eProgress.emit(E_PROGRESS.PROGRESS_ZIP, 'Scanning zips', 0)
|
||||
console.log('[scanning] started')
|
||||
|
||||
for (let zipPath of filepaths) {
|
||||
const zip = new StreamZip.async({ file: zipPath })
|
||||
|
||||
let promise = zip
|
||||
.entries()
|
||||
.then(entries => {
|
||||
Object.values(entries).forEach(entry => parseRawEntry(entry, zipPath, dupeDb))
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
throw new ZipError(`Error reading zip file: ${zipPath}`)
|
||||
})
|
||||
.finally(() => {
|
||||
zip.close()
|
||||
})
|
||||
|
||||
scanPromises.push(promise)
|
||||
}
|
||||
|
||||
Promise.all(scanPromises).then(() => console.log('[scanning] complete'))
|
||||
|
||||
return Promise.all(scanPromises).then(() => dupeDb)
|
||||
}
|
||||
|
||||
function streamEntry(zip: StreamZip, entry: ZipEntry) {
|
||||
return new Promise<[string, Buffer]>((resolve, reject) => {
|
||||
zip.stream(entry.name, (err, stream) => {
|
||||
if (err || !stream) {
|
||||
console.error(`Error streaming ${entry.name}:`, err)
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
let chunks: any = []
|
||||
stream.on('data', chunk => chunks.push(chunk))
|
||||
stream.on('end', () => resolve([entry.name, Buffer.concat(chunks)]))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function handleEntry([entryName, buffer]: [string, Buffer], handler: Handler) {
|
||||
handler(entryName, buffer, identifyEntry(entryName))
|
||||
// console.log(`[streaming] ${entryName} handled`)
|
||||
return StreamCodes.STREAM_HANDLED
|
||||
}
|
||||
|
||||
function indexDupes(dupeDb: DupeDb) {
|
||||
console.log('[indexing] started')
|
||||
let indexedEntries: Indexed = {},
|
||||
totalEntries = Object.keys(dupeDb.entries).length
|
||||
|
||||
eProgress.emit(E_PROGRESS.PROGRESS_ZIP, 'Indexing entries', 0)
|
||||
|
||||
for (let [entryName, [, zipPath]] of Object.entries(dupeDb.entries)) {
|
||||
if (dupeDb.multiple[entryName]) {
|
||||
dupeDb.multiple[entryName].push(zipPath)
|
||||
indexedEntries[entryName] = dupeDb.multiple[entryName]
|
||||
} else indexedEntries[entryName] = zipPath
|
||||
|
||||
let percent = Object.keys(indexedEntries).length / totalEntries
|
||||
eProgress.emit(E_PROGRESS.PROGRESS_ZIP, 'Indexing entries', percent)
|
||||
}
|
||||
|
||||
// for (let [entryName] of Object.entries(indexedEntries)) {
|
||||
// const type = identifyEntry(entryName),
|
||||
// { fileName, inbox } = identifyEntryProperties(entryName)
|
||||
|
||||
// if (type == EntryTypes.INBOX_JSON || type == EntryTypes.META) continue
|
||||
|
||||
// // const exists = checkForExisting(type, fileName, inbox)
|
||||
|
||||
// // if (exists) {
|
||||
// // // console.log(`[indexing] ${fileName} already exists in the database`)
|
||||
// // delete indexedEntries[entryName]
|
||||
// // }
|
||||
|
||||
// let percent = (Object.keys(indexedEntries).length / totalEntries) * 50 + 50
|
||||
// eProgress.emit(E_PROGRESS.PROGRESS_ZIP, 'Indexing entries', percent)
|
||||
// }
|
||||
|
||||
console.log('[indexing] complete')
|
||||
return indexedEntries
|
||||
}
|
||||
|
||||
function streamZips(filePaths: string[], index: Indexed, handler: Handler) {
|
||||
let zipPromises: Promise<void>[] = []
|
||||
|
||||
var totalEntries = Object.keys(index).length,
|
||||
scope = Math.floor(totalEntries / 200),
|
||||
entriesDone = 0
|
||||
|
||||
console.log(`[streaming] started`)
|
||||
|
||||
for (let zipPath of filePaths) {
|
||||
let promise = new Promise<void>((resolve, reject) => {
|
||||
eProgress.emit(E_PROGRESS.PROGRESS_ZIP, 'Streaming entries', 0)
|
||||
|
||||
const zip = new StreamZip({ file: zipPath, storeEntries: true })
|
||||
|
||||
// Once the zip is ready, process each entry
|
||||
zip.on('ready', () => {
|
||||
let entryPromises = Object.values(zip.entries())
|
||||
// db handling
|
||||
.map(async entry => {
|
||||
if (entry.isDirectory) return StreamCodes.STREAM_SKIPPED
|
||||
|
||||
// handle mismatched entries
|
||||
if (Array.isArray(index[entry.name])) {
|
||||
return streamEntry(zip, entry).then(([filename, buff]) => {
|
||||
if (buff.every(byte => byte == 0)) return StreamCodes.STREAM_INVALID
|
||||
else return handleEntry([filename, buff], handler)
|
||||
})
|
||||
} else if (index[entry.name] != zipPath) return StreamCodes.STREAM_SKIPPED
|
||||
|
||||
return streamEntry(zip, entry).then(data => handleEntry(data, handler))
|
||||
})
|
||||
// progress tracking
|
||||
.map(p =>
|
||||
p.then(code => {
|
||||
if (code == StreamCodes.STREAM_HANDLED) entriesDone++
|
||||
|
||||
if (entriesDone > 0)
|
||||
// if (entriesDone % scope == 0) {
|
||||
eProgress.emit(
|
||||
E_PROGRESS.PROGRESS_ZIP,
|
||||
'Streaming entries',
|
||||
(entriesDone / totalEntries) * 100
|
||||
)
|
||||
// }
|
||||
})
|
||||
)
|
||||
|
||||
Promise.all(entryPromises).then(() => {
|
||||
zip.close()
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
|
||||
// Handle errors
|
||||
zip.on('error', err => {
|
||||
throw new ZipError(`Error reading zip file: ${zipPath}`)
|
||||
})
|
||||
})
|
||||
zipPromises.push(promise)
|
||||
}
|
||||
|
||||
Promise.all(zipPromises).then(() => console.log(`[streaming] complete`))
|
||||
|
||||
return Promise.all(zipPromises).then(() => totalEntries)
|
||||
}
|
||||
|
||||
function rawFacebookZipsToIndexedBlobs(filePaths: string[], handler: Handler, progress: Progress) {
|
||||
let lastProgressTime = process.hrtime.bigint()
|
||||
|
||||
eProgress.on(E_PROGRESS.PROGRESS_ZIP, (title, percent) => {
|
||||
let now = process.hrtime.bigint()
|
||||
|
||||
if (Number(now - lastProgressTime) > 25e7) {
|
||||
lastProgressTime = now
|
||||
progress(title, percent)
|
||||
}
|
||||
})
|
||||
|
||||
return scanZips(filePaths)
|
||||
.then(dupeDb => indexDupes(dupeDb))
|
||||
.then(index => streamZips(filePaths, index, handler))
|
||||
.finally(() => eProgress.off(E_PROGRESS.PROGRESS_ZIP, progress))
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
export default rawFacebookZipsToIndexedBlobs
|
||||
|
||||
// rawFacebookZipsToIndexedBlobs(
|
||||
// ['/vault/Downloads/smol/all-json-no-media.zip'],
|
||||
// async (entryName, blob, type) => {
|
||||
// // handler
|
||||
// // console.log(entryName, type)
|
||||
// },
|
||||
// (title, percent) => {
|
||||
// // progress
|
||||
// }
|
||||
// )
|
||||
+4
-3
@@ -1,6 +1,5 @@
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
|
||||
// webpack.config.js
|
||||
module.exports = [
|
||||
{
|
||||
mode: 'development',
|
||||
@@ -13,7 +12,6 @@ module.exports = [
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
// include: /src/,
|
||||
use: [{ loader: 'ts-loader' }],
|
||||
},
|
||||
{
|
||||
@@ -26,6 +24,10 @@ module.exports = [
|
||||
path: __dirname + '/build',
|
||||
filename: 'electron.js',
|
||||
},
|
||||
// Mark better-sqlite3 as an external module
|
||||
externals: {
|
||||
'better-sqlite3': 'commonjs better-sqlite3',
|
||||
},
|
||||
},
|
||||
{
|
||||
entry: './electron/preload.ts',
|
||||
@@ -37,7 +39,6 @@ module.exports = [
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
// include: /src/,
|
||||
use: [{ loader: 'ts-loader' }],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user