Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Add default community avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Feb 9, 2021
1 parent f0d9660 commit 60c0a4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Expand Up @@ -10,7 +10,8 @@ import * as os from 'os'
import { setOrigin, getDomain, parseAcctUrl, usernameToUserId, constructUserUrl, DEBUG_MODE_PORTS_MAP } from './lib/strings.js'
import * as dbGetters from './db/getters.js'

const DEFAULT_USER_THUMB_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), 'static', 'img', 'default-user-thumb.jpg')
const DEFAULT_USER_AVATAR_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), 'static', 'img', 'default-user-avatar.jpg')
const DEFAULT_COMMUNITY_AVATAR_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), 'static', 'img', 'default-community-avatar.jpg')

let app

Expand Down Expand Up @@ -76,18 +77,23 @@ export async function start ({port, configDir, simulateHyperspace, domain, debug
})

app.get('/ctzn/avatar/:username([^\/]{3,})', async (req, res) => {
let userDb
try {
const userId = usernameToUserId(req.params.username)
const userDb = db.publicUserDbs.get(userId)
userDb = db.publicUserDbs.get(userId)
if (!userDb) {
res.sendFile(DEFAULT_USER_THUMB_PATH)
res.sendFile(DEFAULT_USER_AVATAR_PATH)
return
}

const s = await userDb.blobs.createReadStream('avatar')
s.pipe(res)
} catch (e) {
res.sendFile(DEFAULT_USER_THUMB_PATH)
if (userDb && userDb.dbType === 'ctzn.network/public-community-db') {
res.sendFile(DEFAULT_COMMUNITY_AVATAR_PATH)
} else {
res.sendFile(DEFAULT_USER_AVATAR_PATH)
}
}
})

Expand Down
Binary file added static/img/default-community-avatar.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes

0 comments on commit 60c0a4d

Please sign in to comment.