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
616 B
JavaScript
Raw Normal View History

2020-12-24 04:00:37 -08:00
import {fallbackAvatar, gravatar, now} from "../src/helpers";
2020-11-02 12:12:15 -08:00
import SQL from "sql-template-strings";
export default async (db, user) => {
2020-12-24 04:00:37 -08:00
if (user.avatarSource === 'gravatar') {
return gravatar(user);
} else if (user.avatarSource) {
2020-11-02 12:12:15 -08:00
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;
}
}
2020-12-24 04:00:37 -08:00
return fallbackAvatar(user);
2020-11-02 12:12:15 -08:00
}