tangled
alpha
login
or
join now
hexmani.ac
/
clippr
12
fork
atom
social bookmarking for atproto
12
fork
atom
overview
issues
1
pulls
pipelines
[backend] support updates for profiles
hexmani.ac
7 months ago
f7aace82
08c2fef2
verified
This commit was signed with the committer's
known signature
.
hexmani.ac
SSH Key Fingerprint:
SHA256:tV3v2UX4P3x12jjh+mHVzpRQ4ZhNBCHoFwqRiYzzTcM=
+23
-2
1 changed file
expand all
collapse all
unified
split
backend
src
network
commit.ts
+23
-2
backend/src/network/commit.ts
···
18
18
import { validateClip, validateProfile, validateTag } from "./validator.js";
19
19
import { convertDidToString } from "./converters.js";
20
20
import { hashString } from "../hasher.js";
21
21
+
import { eq } from "drizzle-orm";
21
22
22
23
const db = Database.getInstance().getDb();
23
24
···
165
166
export async function handleProfile(
166
167
event: CommitEvent<`social.clippr.${string}`>,
167
168
): Promise<void> {
168
168
-
if (event.commit.operation !== "create") {
169
169
+
if (event.commit.operation === "delete") {
169
170
Logger.warn(
170
171
`Operation '${event.commit.operation}' for ${event.commit.collection} not supported. Ignoring.`,
171
172
);
172
173
return;
173
173
-
} // We currently do not handle these.
174
174
+
} // We currently do not handle deletes.
174
175
175
176
if (event.commit.record.$type !== "social.clippr.actor.profile") {
176
177
Logger.verbose(
···
241
242
242
243
// Independent validations
243
244
if (!(await validateProfile(record))) {
245
245
+
return;
246
246
+
}
247
247
+
248
248
+
if (event.commit.operation === "update") {
249
249
+
await db
250
250
+
.update(usersTable)
251
251
+
.set({
252
252
+
did: convertDidToString(event.did),
253
253
+
cid: event.commit.cid,
254
254
+
timestamp: convertMicroToDate(event.time_us),
255
255
+
createdAt: new Date(record.createdAt),
256
256
+
displayName: record.displayName,
257
257
+
avatar: record.avatar?.ref.$link,
258
258
+
description: record.description,
259
259
+
})
260
260
+
.where(eq(usersTable.did, convertDidToString(event.did)))
261
261
+
.execute();
262
262
+
263
263
+
Logger.verbose(`Updated profile: ${convertDidToString(event.did)}`, event);
264
264
+
244
265
return;
245
266
}
246
267