fix: 🐛 update correctly

also remove lastVerified, was being weird
This commit is contained in:
ThatOneCalculator 2023-07-16 19:33:48 -07:00
parent 34cfe9c15c
commit 11fefc5557
No known key found for this signature in database
GPG key ID: 8703CACD01000000
5 changed files with 39 additions and 31 deletions

3
.gitignore vendored
View file

@ -27,7 +27,7 @@ coverage
!/.config/helm_values_example.yml !/.config/helm_values_example.yml
!/.config/LICENSE !/.config/LICENSE
#docker dev config # docker dev config
/dev/docker-compose.yml /dev/docker-compose.yml
# misskey # misskey
@ -46,6 +46,7 @@ files
ormconfig.json ormconfig.json
packages/backend/assets/instance.css packages/backend/assets/instance.css
packages/backend/assets/sounds/None.mp3 packages/backend/assets/sounds/None.mp3
packages/backend/assets/LICENSE
!packages/backend/src/db !packages/backend/src/db

View file

@ -52,7 +52,6 @@ export class UserProfile {
name: string; name: string;
value: string; value: string;
verified?: boolean; verified?: boolean;
lastVerified?: Date;
}[]; }[];
@Column("varchar", { @Column("varchar", {

View file

@ -26,10 +26,7 @@ export async function verifyLinks(
x.name !== "" && x.name !== "" &&
typeof x.value === "string" && typeof x.value === "string" &&
x.value !== "" && x.value !== "" &&
x.value.startsWith("http") && x.value.startsWith("http")
((x.lastVerified &&
x.lastVerified.getTime() < Date.now() - 1000 * 60 * 60 * 24 * 14) ||
!x.lastVerified),
) )
.map(async (x) => { .map(async (x) => {
const relMeLinks = await getRelMeLinks(x.value); const relMeLinks = await getRelMeLinks(x.value);
@ -40,7 +37,6 @@ export async function verifyLinks(
name: x.name, name: x.name,
value: x.value, value: x.value,
verified: verified, verified: verified,
lastVerified: new Date(),
}; };
}); });
if (fields.length > 0) { if (fields.length > 0) {

View file

@ -16,6 +16,7 @@ import { getRelMeLinks } from "@/services/fetch-rel-me.js";
import { ApiError } from "../../error.js"; import { ApiError } from "../../error.js";
import config from "@/config/index.js"; import config from "@/config/index.js";
import define from "../../define.js"; import define from "../../define.js";
import type * as misskey from "calckey-js";
export const meta = { export const meta = {
tags: ["account"], tags: ["account"],
@ -137,6 +138,17 @@ export const paramDef = {
}, },
} as const; } 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) => { export default define(meta, paramDef, async (ps, _user, token) => {
const user = await Users.findOneByOrFail({ id: _user.id }); const user = await Users.findOneByOrFail({ id: _user.id });
const isSecure = token == null; const isSecure = token == null;
@ -236,29 +248,25 @@ export default define(meta, paramDef, async (ps, _user, token) => {
} }
if (ps.fields) { if (ps.fields) {
profileUpdates.fields = ps.fields profileUpdates.fields = await Promise.all(
.filter( ps.fields
(x) => .filter(
typeof x.name === "string" && (x: misskey.entities.UserDetailed.fields) =>
x.name !== "" && typeof x.name === "string" &&
typeof x.value === "string" && x.name !== "" &&
x.value !== "", typeof x.value === "string" &&
) x.value !== "",
.map(async (x) => { )
let verified = false; .map(async (x: misskey.entities.UserDetailed.fields) => {
if (x.value.startsWith("http")) { return {
const relMeLinks = await getRelMeLinks(x.value); name: x.name,
verified = relMeLinks.some((link) => value: x.value,
link.includes(`${config.host}/@${user.username}`), verified: x.value.startsWith("http")
); ? await verifyLink(x.value, user.username)
} : null,
return { };
name: x.name, }),
value: x.value, );
verified: verified,
lastVerified: new Date(),
};
});
} }
//#region emojis/tags //#region emojis/tags

View file

@ -38,7 +38,11 @@ export type UserDetailed = UserLite & {
createdAt: DateString; createdAt: DateString;
description: string | null; description: string | null;
ffVisibility: "public" | "followers" | "private"; ffVisibility: "public" | "followers" | "private";
fields: { name: string; value: string }[]; fields: {
name: string;
value: string;
verified?: boolean;
}[];
followersCount: number; followersCount: number;
followingCount: number; followingCount: number;
hasPendingFollowRequestFromYou: boolean; hasPendingFollowRequestFromYou: boolean;