refactor: more common name
This commit is contained in:
parent
cc6b2d578f
commit
2c36844d34
@ -1,5 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Random avatar generator
|
* Identicon generator
|
||||||
|
* https://en.wikipedia.org/wiki/Identicon
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as p from 'pureimage';
|
import * as p from 'pureimage';
|
||||||
@ -34,9 +35,9 @@ const cellSize = actualSize / n;
|
|||||||
const sideN = Math.floor(n / 2);
|
const sideN = Math.floor(n / 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate buffer of random avatar by seed
|
* Generate buffer of an identicon by seed
|
||||||
*/
|
*/
|
||||||
export function genAvatar(seed: string, stream: WriteStream): Promise<void> {
|
export function genIdenticon(seed: string, stream: WriteStream): Promise<void> {
|
||||||
const rand = gen.create(seed);
|
const rand = gen.create(seed);
|
||||||
const canvas = p.make(size, size);
|
const canvas = p.make(size, size);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
@ -159,7 +159,7 @@ export class UserRepository extends Repository<User> {
|
|||||||
if (user.avatarUrl) {
|
if (user.avatarUrl) {
|
||||||
return user.avatarUrl;
|
return user.avatarUrl;
|
||||||
} else {
|
} else {
|
||||||
return `${config.url}/random-avatar/${user.id}`;
|
return `${config.url}/identicon/${user.id}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import Logger from '@/services/logger';
|
|||||||
import { envOption } from '../env';
|
import { envOption } from '../env';
|
||||||
import { UserProfiles, Users } from '@/models/index';
|
import { UserProfiles, Users } from '@/models/index';
|
||||||
import { networkChart } from '@/services/chart/index';
|
import { networkChart } from '@/services/chart/index';
|
||||||
import { genAvatar } from '@/misc/gen-avatar';
|
import { genIdenticon } from '@/misc/gen-identicon';
|
||||||
import { createTemp } from '@/misc/create-temp';
|
import { createTemp } from '@/misc/create-temp';
|
||||||
import { publishMainStream } from '@/services/stream';
|
import { publishMainStream } from '@/services/stream';
|
||||||
import * as Acct from 'misskey-js/built/acct';
|
import * as Acct from 'misskey-js/built/acct';
|
||||||
@ -84,9 +84,9 @@ router.get('/avatar/@:acct', async ctx => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/random-avatar/:x', async ctx => {
|
router.get('/identicon/:x', async ctx => {
|
||||||
const [temp] = await createTemp();
|
const [temp] = await createTemp();
|
||||||
await genAvatar(ctx.params.x, fs.createWriteStream(temp));
|
await genIdenticon(ctx.params.x, fs.createWriteStream(temp));
|
||||||
ctx.set('Content-Type', 'image/png');
|
ctx.set('Content-Type', 'image/png');
|
||||||
ctx.body = fs.createReadStream(temp);
|
ctx.body = fs.createReadStream(temp);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user