feat: support concurrent Reddit accounts
This commit is contained in:
1 parent
d819a0f1e6
commit
16a31335d0
51 files changed
+3241
-250
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { RedditAccountOwnerSchema } from './session.js';
|
||||
|
||||
export const ActivityTypeSchema = z.union([
|
||||
z.literal('sent'),
|
||||
@@ -17,6 +18,7 @@ export const ActivityItemSchema = z.strictObject({
|
||||
imageUrl: z.string().optional(),
|
||||
postTitle: z.string().optional(),
|
||||
postUrl: z.string().optional(),
|
||||
owner: RedditAccountOwnerSchema.optional(),
|
||||
});
|
||||
|
||||
export const ActivityResponseSchema = z.array(ActivityItemSchema);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { ErrorResponseSchema, RejectedActionResponseSchema } from './common.js';
|
||||
import { RedditAccountOwnerSchema } from './session.js';
|
||||
|
||||
export const ChatMediaSchema = z.strictObject({
|
||||
originalUrl: z.string(),
|
||||
@@ -25,6 +26,7 @@ export const ActiveChatSchema = z.strictObject({
|
||||
messages: z.array(ChatMessageSchema).optional(),
|
||||
originMessage: z.string().optional(),
|
||||
hasReceivedImages: z.boolean().optional(),
|
||||
owner: RedditAccountOwnerSchema.optional(),
|
||||
});
|
||||
export const ChatsResponseSchema = z.array(ActiveChatSchema);
|
||||
export const ConversationsResponseSchema = ChatsResponseSchema;
|
||||
@@ -75,6 +77,7 @@ export const ConversationDetailResponseSchema = ActiveChatSchema.extend({
|
||||
export const SuggestedReplyResponseSchema = z.strictObject({ suggestedReply: z.string() });
|
||||
export const SendReplyRequestSchema = z.strictObject({ message: z.string().min(1) });
|
||||
export const StartConversationRequestSchema = z.strictObject({
|
||||
accountId: z.string().min(1),
|
||||
username: z.string().min(1),
|
||||
message: z.string().min(1),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { RejectedActionResponseSchema, SuccessResponseSchema } from './common.js';
|
||||
import { RedditAccountOwnerSchema } from './session.js';
|
||||
|
||||
export const MediaItemSchema = z.strictObject({
|
||||
id: z.string(),
|
||||
@@ -12,6 +13,7 @@ export const MediaItemSchema = z.strictObject({
|
||||
relativePath: z.string(),
|
||||
createdAt: z.number(),
|
||||
urlPath: z.string(),
|
||||
owner: RedditAccountOwnerSchema.optional(),
|
||||
});
|
||||
export const MediaResponseSchema = z.array(MediaItemSchema);
|
||||
export const MediaSyncStatusSchema = z.strictObject({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { RedditAccountOwnerSchema } from './session.js';
|
||||
|
||||
export const SentMessageSchema = z.strictObject({
|
||||
id: z.number(),
|
||||
@@ -17,6 +18,7 @@ export const SentMessageSchema = z.strictObject({
|
||||
postUrl: z.string().optional(),
|
||||
postImageUrl: z.string().optional(),
|
||||
postImageAnalysis: z.string().optional(),
|
||||
owner: RedditAccountOwnerSchema.optional(),
|
||||
});
|
||||
export const MessagesResponseSchema = z.array(SentMessageSchema);
|
||||
|
||||
@@ -32,6 +34,7 @@ export const ProcessedPostSchema = z.strictObject({
|
||||
processedAt: z.number(),
|
||||
messageSent: z.boolean(),
|
||||
error: z.string().nullable(),
|
||||
owner: RedditAccountOwnerSchema.optional(),
|
||||
});
|
||||
export const ProcessedPostsResponseSchema = z.array(ProcessedPostSchema);
|
||||
|
||||
|
||||
@@ -6,12 +6,28 @@ export const RedditSessionStateSchema = z.union([
|
||||
z.literal('login-required'),
|
||||
z.literal('unreachable'),
|
||||
]);
|
||||
export const RedditAccountSummarySchema = z.strictObject({
|
||||
accountId: z.string().min(1),
|
||||
redditUsername: z.string().min(1),
|
||||
matrixUserId: z.string().min(1),
|
||||
isRunning: z.boolean(),
|
||||
status: z.union([z.literal('authenticated'), z.literal('login-required')]),
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
lastImportedAt: z.number(),
|
||||
});
|
||||
export const RedditAccountOwnerSchema = RedditAccountSummarySchema.pick({
|
||||
accountId: true,
|
||||
redditUsername: true,
|
||||
});
|
||||
export const RedditAccountsResponseSchema = z.array(RedditAccountSummarySchema);
|
||||
export const LoginStatusResponseSchema = z.union([
|
||||
z.strictObject({ ready: z.literal(false), error: z.string() }),
|
||||
z.strictObject({
|
||||
ready: z.literal(true),
|
||||
loggedIn: z.boolean(),
|
||||
status: RedditSessionStateSchema,
|
||||
accountId: z.string().min(1).nullable().optional(),
|
||||
username: z.string().min(1).nullable().optional(),
|
||||
}),
|
||||
z.strictObject({
|
||||
@@ -39,10 +55,20 @@ export const RedditCookieImportRequestSchema = z.strictObject({
|
||||
}),
|
||||
});
|
||||
export const RedditCookieImportResponseSchema = z.union([
|
||||
z.strictObject({ ok: z.literal(true), status: z.literal('authenticated') }),
|
||||
z.strictObject({
|
||||
ok: z.literal(true),
|
||||
status: z.literal('authenticated'),
|
||||
account: RedditAccountSummarySchema,
|
||||
}),
|
||||
z.strictObject({ ok: z.literal(false), error: z.string() }),
|
||||
]);
|
||||
export const RedditAccountActivationResponseSchema = z.union([
|
||||
z.strictObject({ ok: z.literal(true), account: RedditAccountSummarySchema }),
|
||||
z.strictObject({ ok: z.literal(false), error: z.string() }),
|
||||
]);
|
||||
|
||||
export type RedditSessionState = z.infer<typeof RedditSessionStateSchema>;
|
||||
export type LoginStatusResponse = z.infer<typeof LoginStatusResponseSchema>;
|
||||
export type RedditCookieImportRequest = z.infer<typeof RedditCookieImportRequestSchema>;
|
||||
export type RedditAccountSummary = z.infer<typeof RedditAccountSummarySchema>;
|
||||
export type RedditAccountOwner = z.infer<typeof RedditAccountOwnerSchema>;
|
||||
Reference in new issue
Block a user