* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
This commit is contained in:
syuilo
2021-04-24 22:38:24 +09:00
committed by GitHub
parent ccf063709e
commit fec3c70886
32 changed files with 1607 additions and 9 deletions

View File

@ -0,0 +1,29 @@
import define from '../../define';
import { GalleryPosts } from '../../../../models';
export const meta = {
tags: ['gallery'],
requireCredential: false as const,
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost',
}
},
};
export default define(meta, async (ps, me) => {
const query = GalleryPosts.createQueryBuilder('post')
.andWhere('post.createdAt > :date', { date: new Date(Date.now() - (1000 * 60 * 60 * 24 * 3)) })
.andWhere('post.likedCount > 0')
.orderBy('post.likedCount', 'DESC');
const posts = await query.take(10).getMany();
return await GalleryPosts.packMany(posts, me);
});

View File

@ -0,0 +1,28 @@
import define from '../../define';
import { GalleryPosts } from '../../../../models';
export const meta = {
tags: ['gallery'],
requireCredential: false as const,
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost',
}
},
};
export default define(meta, async (ps, me) => {
const query = GalleryPosts.createQueryBuilder('post')
.andWhere('post.likedCount > 0')
.orderBy('post.likedCount', 'DESC');
const posts = await query.take(10).getMany();
return await GalleryPosts.packMany(posts, me);
});

View File

@ -0,0 +1,43 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../define';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { GalleryPosts } from '../../../../models';
export const meta = {
tags: ['gallery'],
params: {
limit: {
validator: $.optional.num.range(1, 100),
default: 10
},
sinceId: {
validator: $.optional.type(ID),
},
untilId: {
validator: $.optional.type(ID),
},
},
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost',
}
},
};
export default define(meta, async (ps, me) => {
const query = makePaginationQuery(GalleryPosts.createQueryBuilder('post'), ps.sinceId, ps.untilId)
.innerJoinAndSelect('post.user', 'user');
const posts = await query.take(ps.limit!).getMany();
return await GalleryPosts.packMany(posts, me);
});

View File

@ -0,0 +1,76 @@
import $ from 'cafy';
import * as ms from 'ms';
import define from '../../../define';
import { ID } from '../../../../../misc/cafy-id';
import { DriveFiles, GalleryPosts } from '../../../../../models';
import { genId } from '../../../../../misc/gen-id';
import { GalleryPost } from '../../../../../models/entities/gallery-post';
import { ApiError } from '../../../error';
export const meta = {
tags: ['gallery'],
requireCredential: true as const,
kind: 'write:gallery',
limit: {
duration: ms('1hour'),
max: 300
},
params: {
title: {
validator: $.str.min(1),
},
description: {
validator: $.optional.nullable.str,
},
fileIds: {
validator: $.arr($.type(ID)).unique().range(1, 32),
},
isSensitive: {
validator: $.optional.bool,
default: false,
},
},
res: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost',
},
errors: {
}
};
export default define(meta, async (ps, user) => {
const files = (await Promise.all(ps.fileIds.map(fileId =>
DriveFiles.findOne({
id: fileId,
userId: user.id
})
))).filter(file => file != null);
if (files.length === 0) {
throw new Error();
}
const post = await GalleryPosts.insert(new GalleryPost({
id: genId(),
createdAt: new Date(),
updatedAt: new Date(),
title: ps.title,
description: ps.description,
userId: user.id,
isSensitive: ps.isSensitive,
fileIds: files.map(file => file.id)
})).then(x => GalleryPosts.findOneOrFail(x.identifiers[0]));
return await GalleryPosts.pack(post, user);
});

View File

@ -0,0 +1,71 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { GalleryPosts, GalleryLikes } from '../../../../../models';
import { genId } from '@/misc/gen-id';
export const meta = {
tags: ['gallery'],
requireCredential: true as const,
kind: 'write:gallery-likes',
params: {
postId: {
validator: $.type(ID),
}
},
errors: {
noSuchPost: {
message: 'No such post.',
code: 'NO_SUCH_POST',
id: '56c06af3-1287-442f-9701-c93f7c4a62ff'
},
yourPost: {
message: 'You cannot like your post.',
code: 'YOUR_POST',
id: 'f78f1511-5ebc-4478-a888-1198d752da68'
},
alreadyLiked: {
message: 'The post has already been liked.',
code: 'ALREADY_LIKED',
id: '40e9ed56-a59c-473a-bf3f-f289c54fb5a7'
},
}
};
export default define(meta, async (ps, user) => {
const post = await GalleryPosts.findOne(ps.postId);
if (post == null) {
throw new ApiError(meta.errors.noSuchPost);
}
if (post.userId === user.id) {
throw new ApiError(meta.errors.yourPost);
}
// if already liked
const exist = await GalleryLikes.findOne({
postId: post.id,
userId: user.id
});
if (exist != null) {
throw new ApiError(meta.errors.alreadyLiked);
}
// Create like
await GalleryLikes.insert({
id: genId(),
createdAt: new Date(),
postId: post.id,
userId: user.id
});
GalleryPosts.increment({ id: post.id }, 'likedCount', 1);
});

View File

@ -0,0 +1,43 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { GalleryPosts } from '@/models';
export const meta = {
tags: ['gallery'],
requireCredential: false as const,
params: {
postId: {
validator: $.type(ID),
},
},
errors: {
noSuchPost: {
message: 'No such post.',
code: 'NO_SUCH_POST',
id: '1137bf14-c5b0-4604-85bb-5b5371b1cd45'
},
},
res: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost'
}
};
export default define(meta, async (ps, me) => {
const post = await GalleryPosts.findOne({
id: ps.postId,
});
if (post == null) {
throw new ApiError(meta.errors.noSuchPost);
}
return await GalleryPosts.pack(post, me);
});

View File

@ -0,0 +1,54 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { GalleryPosts, GalleryLikes } from '../../../../../models';
export const meta = {
tags: ['gallery'],
requireCredential: true as const,
kind: 'write:gallery-likes',
params: {
postId: {
validator: $.type(ID),
}
},
errors: {
noSuchPost: {
message: 'No such post.',
code: 'NO_SUCH_POST',
id: 'c32e6dd0-b555-4413-925e-b3757d19ed84'
},
notLiked: {
message: 'You have not liked that post.',
code: 'NOT_LIKED',
id: 'e3e8e06e-be37-41f7-a5b4-87a8250288f0'
},
}
};
export default define(meta, async (ps, user) => {
const post = await GalleryPosts.findOne(ps.postId);
if (post == null) {
throw new ApiError(meta.errors.noSuchPost);
}
const exist = await GalleryLikes.findOne({
postId: post.id,
userId: user.id
});
if (exist == null) {
throw new ApiError(meta.errors.notLiked);
}
// Delete like
await GalleryLikes.delete(exist.id);
GalleryPosts.decrement({ id: post.id }, 'likedCount', 1);
});

View File

@ -0,0 +1,57 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { GalleryLikes } from '../../../../../models';
import { makePaginationQuery } from '../../../common/make-pagination-query';
export const meta = {
tags: ['account', 'gallery'],
requireCredential: true as const,
kind: 'read:gallery-likes',
params: {
limit: {
validator: $.optional.num.range(1, 100),
default: 10
},
sinceId: {
validator: $.optional.type(ID),
},
untilId: {
validator: $.optional.type(ID),
},
},
res: {
type: 'object' as const,
optional: false as const, nullable: false as const,
properties: {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
},
page: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost'
}
}
}
};
export default define(meta, async (ps, user) => {
const query = makePaginationQuery(GalleryLikes.createQueryBuilder('like'), ps.sinceId, ps.untilId)
.andWhere(`like.userId = :meId`, { meId: user.id })
.leftJoinAndSelect('like.post', 'post');
const likes = await query
.take(ps.limit!)
.getMany();
return await GalleryLikes.packMany(likes, user);
});

View File

@ -0,0 +1,49 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { GalleryPosts } from '../../../../../models';
import { makePaginationQuery } from '../../../common/make-pagination-query';
export const meta = {
tags: ['account', 'gallery'],
requireCredential: true as const,
kind: 'read:gallery',
params: {
limit: {
validator: $.optional.num.range(1, 100),
default: 10
},
sinceId: {
validator: $.optional.type(ID),
},
untilId: {
validator: $.optional.type(ID),
},
},
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'GalleryPost'
}
}
};
export default define(meta, async (ps, user) => {
const query = makePaginationQuery(GalleryPosts.createQueryBuilder('post'), ps.sinceId, ps.untilId)
.andWhere(`post.userId = :meId`, { meId: user.id });
const posts = await query
.take(ps.limit!)
.getMany();
return await GalleryPosts.packMany(posts, user);
});

View File

@ -0,0 +1,39 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { GalleryPosts } from '../../../../../models';
import { makePaginationQuery } from '../../../common/make-pagination-query';
export const meta = {
tags: ['users', 'gallery'],
params: {
userId: {
validator: $.type(ID),
},
limit: {
validator: $.optional.num.range(1, 100),
default: 10
},
sinceId: {
validator: $.optional.type(ID),
},
untilId: {
validator: $.optional.type(ID),
},
}
};
export default define(meta, async (ps, user) => {
const query = makePaginationQuery(GalleryPosts.createQueryBuilder('post'), ps.sinceId, ps.untilId)
.andWhere(`post.userId = :userId`, { userId: ps.userId });
const posts = await query
.take(ps.limit!)
.getMany();
return await GalleryPosts.packMany(posts, user);
});

View File

@ -17,7 +17,7 @@ import packFeed from './feed';
import { fetchMeta } from '@/misc/fetch-meta';
import { genOpenapiSpec } from '../api/openapi/gen-spec';
import config from '@/config';
import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips } from '../../models';
import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips, GalleryPosts } from '../../models';
import parseAcct from '@/misc/acct/parse';
import { getNoteSummary } from '@/misc/get-note-summary';
import { getConnection } from 'typeorm';
@ -342,6 +342,29 @@ router.get('/clips/:clip', async ctx => {
ctx.status = 404;
});
// Gallery post
router.get('/gallery/:post', async ctx => {
const post = await GalleryPosts.findOne(ctx.params.post);
if (post) {
const _post = await GalleryPosts.pack(post);
const profile = await UserProfiles.findOneOrFail(post.userId);
const meta = await fetchMeta();
await ctx.render('gallery-post', {
post: _post,
profile,
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl
});
ctx.set('Cache-Control', 'public, max-age=180');
return;
}
ctx.status = 404;
});
// Channel
router.get('/channels/:channel', async ctx => {
const channel = await Channels.findOne({

View File

@ -0,0 +1,35 @@
extends ./base
block vars
- const user = post.user;
- const title = post.title;
- const url = `${config.url}/gallery/${post.id}`;
block title
= `${title} | ${instanceName}`
block desc
meta(name='description' content= post.description)
block og
meta(property='og:type' content='article')
meta(property='og:title' content= title)
meta(property='og:description' content= post.description)
meta(property='og:url' content= url)
meta(property='og:image' content= post.files[0].thumbnailUrl)
block meta
if user.host || profile.noCrawle
meta(name='robots' content='noindex')
meta(name='misskey:user-username' content=user.username)
meta(name='misskey:user-id' content=user.id)
meta(name='twitter:card' content='summary')
// todo
if user.twitter
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
if !user.host
link(rel='alternate' href=url type='application/activity+json')