This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/server/avatar.js

21 lines
549 B
JavaScript

import {gravatar} from "../src/helpers";
import SQL from "sql-template-strings";
const now = Math.floor(Date.now() / 1000);
export default async (db, user) => {
if (user.avatarSource) {
const auth = await db.get(SQL`
SELECT payload FROM authenticators
WHERE type = ${user.avatarSource}
AND userId = ${user.id}
AND (validUntil IS NULL OR validUntil > ${now})
`)
if (auth) {
return JSON.parse(auth.payload).avatar;
}
}
return gravatar(user);
}