mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-01 01:32:09 +01:00
wip
This commit is contained in:
parent
0cffc1cac0
commit
42be937fcb
4 changed files with 77 additions and 5 deletions
|
@ -490,6 +490,9 @@ const endpoints: Endpoint[] = [
|
|||
{
|
||||
name: 'channels/posts'
|
||||
},
|
||||
{
|
||||
name: 'channels'
|
||||
},
|
||||
];
|
||||
|
||||
export default endpoints;
|
||||
|
|
59
src/api/endpoints/channels.ts
Normal file
59
src/api/endpoints/channels.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Channel from '../models/channel';
|
||||
import serialize from '../serializers/channel';
|
||||
|
||||
/**
|
||||
* Get all channels
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} me
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
if (sinceId && maxId) {
|
||||
return rej('cannot set since_id and max_id');
|
||||
}
|
||||
|
||||
// Construct query
|
||||
const sort = {
|
||||
_id: -1
|
||||
};
|
||||
const query = {} as any;
|
||||
if (sinceId) {
|
||||
sort._id = 1;
|
||||
query._id = {
|
||||
$gt: sinceId
|
||||
};
|
||||
} else if (maxId) {
|
||||
query._id = {
|
||||
$lt: maxId
|
||||
};
|
||||
}
|
||||
|
||||
// Issue query
|
||||
const channels = await Channel
|
||||
.find(query, {
|
||||
limit: limit,
|
||||
sort: sort
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(channels.map(async channel =>
|
||||
await serialize(channel, me))));
|
||||
});
|
|
@ -1,4 +1,6 @@
|
|||
<mk-channel>
|
||||
<header><a href={ CONFIG.chUrl }>Misskey Channels</a></header>
|
||||
<hr>
|
||||
<main if={ !fetching }>
|
||||
<h1>{ channel.title }</h1>
|
||||
<p if={ postsFetching }>読み込み中<mk-ellipsis/></p>
|
||||
|
@ -21,10 +23,9 @@
|
|||
<style>
|
||||
:scope
|
||||
display block
|
||||
padding 8px
|
||||
|
||||
main
|
||||
padding 8px
|
||||
|
||||
> main
|
||||
> h1
|
||||
color #f00
|
||||
</style>
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<mk-index>
|
||||
<button onclick={ new }>%i18n:ch.tags.mk-index.new%</button>
|
||||
<button onclick={ n }>%i18n:ch.tags.mk-index.new%</button>
|
||||
<hr>
|
||||
<ul if={ channels }>
|
||||
<li each={ channels }><a href={ '/' + this.id }>{ this.title }</a></li>
|
||||
</ul>
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
|
@ -9,9 +13,14 @@
|
|||
this.mixin('api');
|
||||
|
||||
this.on('mount', () => {
|
||||
this.api('channels').then(channels => {
|
||||
this.update({
|
||||
channels: channels
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
this.new = () => {
|
||||
this.n = () => {
|
||||
const title = window.prompt('%i18n:ch.tags.mk-index.channel-title%');
|
||||
|
||||
this.api('channels/create', {
|
||||
|
|
Loading…
Reference in a new issue