fix: 🐛 update correctly
also remove lastVerified, was being weird
This commit is contained in:
parent
34cfe9c15c
commit
11fefc5557
5 changed files with 39 additions and 31 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -27,7 +27,7 @@ coverage
|
|||
!/.config/helm_values_example.yml
|
||||
!/.config/LICENSE
|
||||
|
||||
#docker dev config
|
||||
# docker dev config
|
||||
/dev/docker-compose.yml
|
||||
|
||||
# misskey
|
||||
|
@ -46,6 +46,7 @@ files
|
|||
ormconfig.json
|
||||
packages/backend/assets/instance.css
|
||||
packages/backend/assets/sounds/None.mp3
|
||||
packages/backend/assets/LICENSE
|
||||
|
||||
!packages/backend/src/db
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ export class UserProfile {
|
|||
name: string;
|
||||
value: string;
|
||||
verified?: boolean;
|
||||
lastVerified?: Date;
|
||||
}[];
|
||||
|
||||
@Column("varchar", {
|
||||
|
|
|
@ -26,10 +26,7 @@ export async function verifyLinks(
|
|||
x.name !== "" &&
|
||||
typeof x.value === "string" &&
|
||||
x.value !== "" &&
|
||||
x.value.startsWith("http") &&
|
||||
((x.lastVerified &&
|
||||
x.lastVerified.getTime() < Date.now() - 1000 * 60 * 60 * 24 * 14) ||
|
||||
!x.lastVerified),
|
||||
x.value.startsWith("http")
|
||||
)
|
||||
.map(async (x) => {
|
||||
const relMeLinks = await getRelMeLinks(x.value);
|
||||
|
@ -40,7 +37,6 @@ export async function verifyLinks(
|
|||
name: x.name,
|
||||
value: x.value,
|
||||
verified: verified,
|
||||
lastVerified: new Date(),
|
||||
};
|
||||
});
|
||||
if (fields.length > 0) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import { getRelMeLinks } from "@/services/fetch-rel-me.js";
|
|||
import { ApiError } from "../../error.js";
|
||||
import config from "@/config/index.js";
|
||||
import define from "../../define.js";
|
||||
import type * as misskey from "calckey-js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["account"],
|
||||
|
@ -137,6 +138,17 @@ export const paramDef = {
|
|||
},
|
||||
} as const;
|
||||
|
||||
async function verifyLink(link: string, username: string): Promise<boolean> {
|
||||
let verified = false;
|
||||
if (link.startsWith("http")) {
|
||||
const relMeLinks = await getRelMeLinks(link);
|
||||
verified = relMeLinks.some((href) =>
|
||||
href.includes(`${config.host}/@${username}`),
|
||||
);
|
||||
}
|
||||
return verified;
|
||||
}
|
||||
|
||||
export default define(meta, paramDef, async (ps, _user, token) => {
|
||||
const user = await Users.findOneByOrFail({ id: _user.id });
|
||||
const isSecure = token == null;
|
||||
|
@ -236,29 +248,25 @@ export default define(meta, paramDef, async (ps, _user, token) => {
|
|||
}
|
||||
|
||||
if (ps.fields) {
|
||||
profileUpdates.fields = ps.fields
|
||||
profileUpdates.fields = await Promise.all(
|
||||
ps.fields
|
||||
.filter(
|
||||
(x) =>
|
||||
(x: misskey.entities.UserDetailed.fields) =>
|
||||
typeof x.name === "string" &&
|
||||
x.name !== "" &&
|
||||
typeof x.value === "string" &&
|
||||
x.value !== "",
|
||||
)
|
||||
.map(async (x) => {
|
||||
let verified = false;
|
||||
if (x.value.startsWith("http")) {
|
||||
const relMeLinks = await getRelMeLinks(x.value);
|
||||
verified = relMeLinks.some((link) =>
|
||||
link.includes(`${config.host}/@${user.username}`),
|
||||
);
|
||||
}
|
||||
.map(async (x: misskey.entities.UserDetailed.fields) => {
|
||||
return {
|
||||
name: x.name,
|
||||
value: x.value,
|
||||
verified: verified,
|
||||
lastVerified: new Date(),
|
||||
verified: x.value.startsWith("http")
|
||||
? await verifyLink(x.value, user.username)
|
||||
: null,
|
||||
};
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
//#region emojis/tags
|
||||
|
|
|
@ -38,7 +38,11 @@ export type UserDetailed = UserLite & {
|
|||
createdAt: DateString;
|
||||
description: string | null;
|
||||
ffVisibility: "public" | "followers" | "private";
|
||||
fields: { name: string; value: string }[];
|
||||
fields: {
|
||||
name: string;
|
||||
value: string;
|
||||
verified?: boolean;
|
||||
}[];
|
||||
followersCount: number;
|
||||
followingCount: number;
|
||||
hasPendingFollowRequestFromYou: boolean;
|
||||
|
|
Loading…
Reference in a new issue