mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Add fetching user statuses
This commit is contained in:
parent
416a7186d1
commit
29f63dfcb7
73
database/entities/DBStatus.ts
Normal file
73
database/entities/DBStatus.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { getConfig } from "@config";
|
||||
import {
|
||||
BaseEntity,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm";
|
||||
import { Status } from "~types/entities/status";
|
||||
import { DBUser } from "./DBUser";
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
@Entity({
|
||||
name: "statuses",
|
||||
})
|
||||
export class DBStatus extends BaseEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string;
|
||||
|
||||
@ManyToOne(() => DBUser, (user) => user.id)
|
||||
account!: DBUser;
|
||||
|
||||
@CreateDateColumn()
|
||||
created_at!: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated_at!: Date;
|
||||
|
||||
@ManyToOne(() => DBStatus, (status) => status.id, {
|
||||
nullable: true,
|
||||
})
|
||||
reblog?: DBStatus;
|
||||
|
||||
@Column("boolean")
|
||||
isReblog!: boolean;
|
||||
|
||||
toAPI(): Status {
|
||||
return {
|
||||
account: this.account.toAPI(),
|
||||
application: null,
|
||||
bookmarked: false,
|
||||
created_at: this.created_at.toISOString(),
|
||||
emojis: [],
|
||||
favourited: false,
|
||||
favourites_count: 0,
|
||||
id: this.id,
|
||||
in_reply_to_account_id: null,
|
||||
in_reply_to_id: null,
|
||||
language: null,
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
muted: false,
|
||||
pinned: false,
|
||||
poll: null,
|
||||
reblog: this.isReblog ? this.reblog?.toAPI() ?? null : null,
|
||||
reblogged: false,
|
||||
reblogs_count: 0,
|
||||
replies_count: 0,
|
||||
sensitive: false,
|
||||
spoiler_text: "",
|
||||
tags: [],
|
||||
card: null,
|
||||
content: "",
|
||||
uri: `${config.http.base_url}/@${this.account.username}/${this.id}`,
|
||||
url: `${config.http.base_url}/@${this.account.username}/${this.id}`,
|
||||
visibility: "public",
|
||||
quote: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ const config = getConfig();
|
|||
@Entity({
|
||||
name: "users",
|
||||
})
|
||||
export class User extends BaseEntity {
|
||||
export class DBUser extends BaseEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ export class User extends BaseEntity {
|
|||
@UpdateDateColumn()
|
||||
updated_at!: Date;
|
||||
|
||||
toAccount(): Account {
|
||||
toAPI(): Account {
|
||||
return {
|
||||
acct: `@${this.username}@${getHost()}`,
|
||||
avatar: "",
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { User } from "~database/entities/User";
|
||||
import { DBUser } from "~database/entities/DBUser";
|
||||
|
||||
export default async (
|
||||
req: Request,
|
||||
|
|
@ -8,19 +8,17 @@ export default async (
|
|||
): Promise<Response> => {
|
||||
const id = matchedRoute.params.id;
|
||||
|
||||
const user = await User.findOneBy({
|
||||
const user = await DBUser.findOneBy({
|
||||
id,
|
||||
});
|
||||
|
||||
if (!user)
|
||||
return jsonResponse(
|
||||
{
|
||||
statusText: "User not found",
|
||||
error: "User not found",
|
||||
},
|
||||
404
|
||||
);
|
||||
|
||||
return jsonResponse({
|
||||
id,
|
||||
});
|
||||
return jsonResponse(user.toAPI());
|
||||
};
|
||||
|
|
|
|||
53
server/api/v1/accounts/[id]/statuses.ts
Normal file
53
server/api/v1/accounts/[id]/statuses.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { DBStatus } from "~database/entities/DBStatus";
|
||||
import { DBUser } from "~database/entities/DBUser";
|
||||
|
||||
export default async (
|
||||
req: Request,
|
||||
matchedRoute: MatchedRoute
|
||||
): Promise<Response> => {
|
||||
const id = matchedRoute.params.id;
|
||||
|
||||
const {
|
||||
limit,
|
||||
exclude_reblogs,
|
||||
}: {
|
||||
max_id?: string;
|
||||
since_id?: string;
|
||||
min_id?: string;
|
||||
limit?: number;
|
||||
only_media?: boolean;
|
||||
exclude_replies?: boolean;
|
||||
exclude_reblogs?: boolean;
|
||||
pinned?: boolean;
|
||||
tagged?: string;
|
||||
} = matchedRoute.query;
|
||||
|
||||
const user = await DBUser.findOneBy({
|
||||
id,
|
||||
});
|
||||
|
||||
if (!user)
|
||||
return jsonResponse(
|
||||
{
|
||||
error: "User not found",
|
||||
},
|
||||
404
|
||||
);
|
||||
|
||||
const statuses = await DBStatus.find({
|
||||
where: {
|
||||
account: {
|
||||
id: user.id,
|
||||
},
|
||||
isReblog: !exclude_reblogs,
|
||||
},
|
||||
order: {
|
||||
created_at: "DESC",
|
||||
},
|
||||
take: limit ?? 20,
|
||||
});
|
||||
|
||||
return jsonResponse(statuses.map((status) => status.toAPI()));
|
||||
};
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/// <reference path="./entities/account.ts" />
|
||||
/// <reference path="./entities/activity.ts" />
|
||||
/// <reference path="./entities/announcement.ts" />
|
||||
/// <reference path="./entities/application.ts" />
|
||||
/// <reference path="./entities/async_attachment.ts" />
|
||||
/// <reference path="./entities/attachment.ts" />
|
||||
/// <reference path="./entities/card.ts" />
|
||||
/// <reference path="./entities/context.ts" />
|
||||
/// <reference path="./entities/conversation.ts" />
|
||||
/// <reference path="./entities/emoji.ts" />
|
||||
/// <reference path="./entities/featured_tag.ts" />
|
||||
/// <reference path="./entities/field.ts" />
|
||||
/// <reference path="./entities/filter.ts" />
|
||||
/// <reference path="./entities/history.ts" />
|
||||
/// <reference path="./entities/identity_proof.ts" />
|
||||
/// <reference path="./entities/instance.ts" />
|
||||
/// <reference path="./entities/list.ts" />
|
||||
/// <reference path="./entities/marker.ts" />
|
||||
/// <reference path="./entities/mention.ts" />
|
||||
/// <reference path="./entities/notification.ts" />
|
||||
/// <reference path="./entities/poll.ts" />
|
||||
/// <reference path="./entities/poll_option.ts" />
|
||||
/// <reference path="./entities/preferences.ts" />
|
||||
/// <reference path="./entities/push_subscription.ts" />
|
||||
/// <reference path="./entities/relationship.ts" />
|
||||
/// <reference path="./entities/report.ts" />
|
||||
/// <reference path="./entities/results.ts" />
|
||||
/// <reference path="./entities/role.ts" />
|
||||
/// <reference path="./entities/scheduled_status.ts" />
|
||||
/// <reference path="./entities/source.ts" />
|
||||
/// <reference path="./entities/stats.ts" />
|
||||
/// <reference path="./entities/status.ts" />
|
||||
/// <reference path="./entities/status_params.ts" />
|
||||
/// <reference path="./entities/status_source.ts" />
|
||||
/// <reference path="./entities/tag.ts" />
|
||||
/// <reference path="./entities/token.ts" />
|
||||
/// <reference path="./entities/urls.ts" />
|
||||
|
||||
export default MastodonEntity
|
||||
Loading…
Reference in a new issue