Skip to content
Snippets Groups Projects
Commit fa808bf8 authored by roadscape's avatar roadscape
Browse files

adjust fallback to account for posting_json exception

parent 5b65514a
No related branches found
No related tags found
No related merge requests found
...@@ -25,9 +25,6 @@ export async function avatarHandler(ctx: KoaContext) { ...@@ -25,9 +25,6 @@ export async function avatarHandler(ctx: KoaContext) {
interface IExtendedAccount extends Account { interface IExtendedAccount extends Account {
posting_json_metadata?: string; posting_json_metadata?: string;
profile?: {
version: number
};
} }
const [account]: IExtendedAccount[] = await rpcClient.database.getAccounts([username]) const [account]: IExtendedAccount[] = await rpcClient.database.getAccounts([username])
...@@ -35,14 +32,26 @@ export async function avatarHandler(ctx: KoaContext) { ...@@ -35,14 +32,26 @@ export async function avatarHandler(ctx: KoaContext) {
APIError.assert(account, APIError.Code.NoSuchAccount) APIError.assert(account, APIError.Code.NoSuchAccount)
let metadata; let metadata;
try {
metadata = account.posting_json_metadata ? JSON.parse(account.posting_json_metadata) : JSON.parse(account.json_metadata) // read from `posting_json_metadata` if version flag is set
if (metadata && metadata.profile && metadata.profile.version !== 2) { if(account.posting_json_metadata) {
try {
metadata = JSON.parse(account.posting_json_metadata)
if(!metadata.profile || !metadata.profile.version) metadata = {}
} catch (error) {
ctx.log.debug(error, 'unable to parse json_metadata for %s', account.name)
metadata = {}
}
}
// otherwise, fall back to reading from `json_metadata`
if(!metadata) {
try {
metadata = JSON.parse(account.json_metadata) metadata = JSON.parse(account.json_metadata)
} catch (error) {
ctx.log.debug(error, 'unable to parse json_metadata for %s', account.name)
metadata = {}
} }
} catch (error) {
ctx.log.debug(error, 'unable to parse json_metadata for %s', account.name)
metadata = {}
} }
let avatarUrl: string = DefaultAvatar let avatarUrl: string = DefaultAvatar
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment