auron
Version:
Interact with your ATProto labeler from your terminal
110 lines (109 loc) • 4.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformStatusToSubject = void 0;
exports.transformRepoViewToRepo = transformRepoViewToRepo;
exports.transformProfileViewToProfile = transformProfileViewToProfile;
exports.transformRecordViewToRecord = transformRecordViewToRecord;
exports.transformFullStatusFromDatabase = transformFullStatusFromDatabase;
const crypto_1 = __importDefault(require("crypto"));
const transformStatusToSubject = (status) => {
return {
id: status.id,
reviewState: status.reviewState,
createdAt: status.createdAt,
updatedAt: status.updatedAt,
lastReportedAt: status.lastReportedAt || null,
lastReviewedBy: status.lastReviewedBy || null,
lastReviewedAt: status.lastReviewedAt || null,
takendown: status.takendown ? 1 : 0,
subjectRepoHandle: status.subjectRepoHandle,
subjectBlobCids: (status.subjectBlobCids || []).join(","),
tags: (status.tags || []).join(","),
did: (status.subject["did"] ||
status.subject["uri"]
.split("/")
.find((p) => p.startsWith("did:")) ||
""),
recordPath: status.subject["uri"]
? `${status.subject["uri"]}`.split("/").slice(-2).join("/")
: "",
lastAppealedAt: status.lastAppealedAt || null,
suspendUntil: status.suspendUntil || null,
muteUntil: status.muteUntil || null,
muteReportingUntil: status.muteReportingUntil || null,
comment: status.comment || "",
};
};
exports.transformStatusToSubject = transformStatusToSubject;
// Transform repo view to repo row
function transformRepoViewToRepo(repoView) {
return {
did: repoView.did,
handle: repoView.handle,
ip: `${repoView.ip}`,
profile: JSON.stringify(repoView.relatedRecords?.[0] || {}),
indexedAt: repoView.indexedAt,
email: `${repoView.email}`,
emailConfirmedAt: repoView.emailConfirmedAt || null,
threatSignatures: JSON.stringify(repoView.threatSignatures),
labels: JSON.stringify(repoView.labels),
};
}
// Transform profile view to profile row
function transformProfileViewToProfile(profileView) {
return {
did: profileView.did,
handle: profileView.handle,
displayName: profileView.displayName || "",
description: profileView.description || "",
avatar: profileView.avatar || "",
banner: profileView.banner || "",
followersCount: profileView.followersCount || 0,
followsCount: profileView.followsCount || 0,
postsCount: profileView.postsCount || 0,
associated: profileView.associated
? JSON.stringify(profileView.associated)
: undefined,
joinedViaStarterPack: profileView.joinedViaStarterPack
? JSON.stringify(profileView.joinedViaStarterPack)
: undefined,
indexedAt: profileView.indexedAt || undefined,
createdAt: profileView.createdAt || undefined,
viewer: profileView.viewer ? JSON.stringify(profileView.viewer) : undefined,
labels: profileView.labels ? JSON.stringify(profileView.labels) : undefined,
pinnedPost: profileView.pinnedPost
? JSON.stringify(profileView.pinnedPost)
: undefined,
extra: profileView.extra ? JSON.stringify(profileView.extra) : undefined,
syncedAt: new Date().toISOString(),
};
}
function transformRecordViewToRecord(recordView) {
return {
uri: recordView.uri,
cid: recordView.cid,
value: JSON.stringify(recordView.value),
blobCids: JSON.stringify(recordView.blobCids),
indexedAt: recordView.indexedAt,
blobs: JSON.stringify(recordView.blobs),
labels: JSON.stringify(recordView.labels),
};
}
const hashValue = (value) => {
return crypto_1.default.createHash("sha256").update(value).digest("hex");
};
function transformFullStatusFromDatabase(entry) {
return {
...entry,
profile: JSON.parse(entry.profile),
ip: entry.ip ? hashValue(entry.ip) : "",
// email: entry.email ? hashValue(entry.email) : "",
emailDomain: entry.email ? entry.email.split("@")[1] : "",
threatSignatures: JSON.parse(entry.threatSignatures),
blobs: entry.blobs ? JSON.parse(entry.blobs) : entry.blobs,
value: entry.value ? JSON.parse(entry.value) : entry.value,
};
}