feat: replace browser login with imported Reddit sessions
This commit is contained in:
1 parent
2b0545afcf
commit
c483c7b8be
76 files changed
+2048
-2828
No files matched your search
@@ -0,0 +1,34 @@
|
||||
const REDDITBOT_SESSION_FILENAME = 'redditbot-session.json';
|
||||
|
||||
function isRedditDomain(domain) {
|
||||
const normalised = domain.toLowerCase().replace(/^\./, '');
|
||||
return normalised === 'reddit.com' || normalised.endsWith('.reddit.com');
|
||||
}
|
||||
|
||||
function toExportCookie(cookie) {
|
||||
return {
|
||||
name: cookie.name,
|
||||
value: cookie.value,
|
||||
domain: cookie.domain,
|
||||
path: cookie.path,
|
||||
expires: cookie.expirationDate,
|
||||
httpOnly: cookie.httpOnly,
|
||||
secure: cookie.secure,
|
||||
sameSite: cookie.sameSite,
|
||||
};
|
||||
}
|
||||
|
||||
export function createSessionExportDownload(cookies, matrix) {
|
||||
if (!matrix?.homeserver || !matrix?.accessToken || !matrix?.userId) {
|
||||
throw new Error('Open Reddit Chat before exporting so Matrix credentials can be captured.');
|
||||
}
|
||||
const exportFile = {
|
||||
cookies: cookies.filter((cookie) => isRedditDomain(cookie.domain)).map(toExportCookie),
|
||||
matrix,
|
||||
};
|
||||
|
||||
return {
|
||||
filename: REDDITBOT_SESSION_FILENAME,
|
||||
url: `data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(exportFile))}`,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user