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

19 lines
512 B
JavaScript
Raw Normal View History

2020-11-02 12:45:45 -08:00
import {gravatar, now} from "../src/helpers";
2020-11-02 12:12:15 -08:00
import SQL from "sql-template-strings";
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}
2020-11-02 12:45:45 -08:00
AND (validUntil IS NULL OR validUntil > ${now()})
2020-11-02 12:12:15 -08:00
`)
if (auth) {
return JSON.parse(auth.payload).avatar;
}
}
return gravatar(user);
}