Commit ff2c125 1 parent ef6ec28 commit ff2c125 Copy full SHA for ff2c125
File tree 14 files changed +198
-24
lines changed
14 files changed +198
-24
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import { user as endpoint } from '../../Endpoints/mod.ts'
3
+ import { query } from '../../Fetch.js'
4
+
5
+
6
+ const { log } = console ;
7
+
8
+
9
+ export default async function ( userId , options ) {
10
+
11
+ const { content = 'all' } = options ;
12
+
13
+
14
+ const { profile } = await
15
+ fetch ( userId , content ) ;
16
+
17
+
18
+ if ( content === 'all' ) {
19
+
20
+ const response = await
21
+ fetch ( userId , 'collabs' ) ;
22
+
23
+ profile . content . content . collabs
24
+ = response . profile . content . content . collabs ?? [ ] ;
25
+ }
26
+
27
+ return profile ;
28
+ }
29
+
30
+
31
+ async function fetch ( userId , content ) {
32
+ return await query ( {
33
+ url : endpoint . user ( userId ) ,
34
+ parameters : { content }
35
+ } ) ;
36
+ }
Original file line number Diff line number Diff line change
1
+
2
+ import { user as endpoint } from '../../Endpoints/mod.ts'
3
+ import { query } from '../../Fetch.js'
4
+
5
+
6
+ const { log } = console ;
7
+
8
+
9
+ export default async function ( username ) {
10
+
11
+ const response = await query ( {
12
+ url : endpoint . id ,
13
+ parameters : { username }
14
+ } ) ;
15
+
16
+ const { user_id } = response ;
17
+
18
+ return user_id ;
19
+ }
Original file line number Diff line number Diff line change
1
+
2
+ import { UserContentQuery } from '../../Types/UserContentQuery.ts'
3
+ import { Profile } from '../../Types/Profile.ts'
4
+
5
+ import fetchContent from './Content.js'
6
+ import fetchId from './Id.js'
7
+
8
+
9
+
10
+ /**
11
+ * Resolves the users id from their username.
12
+ */
13
+
14
+ export async function id (
15
+
16
+ username : string
17
+
18
+ ) : number {
19
+
20
+ return await
21
+ fetchId ( username ) ;
22
+ }
23
+
24
+
25
+ /**
26
+ * Queries for a users profile and the content specified.
27
+ */
28
+
29
+ export async function content (
30
+
31
+ query : UserContentQuery
32
+
33
+ ) : Profile {
34
+
35
+ return await
36
+ fetchContent ( query ) as Profile ;
37
+ }
Original file line number Diff line number Diff line change 1
1
2
2
3
3
export const domain
4
- = 'https://devrant.com/api/devrant' ;
4
+ = 'https://devrant.com/api' ;
5
+
6
+ export const images
7
+ = 'https://avatars.devrant.com' ;
5
8
6
9
export const rants
7
- = `${ domain } /rants` ;
10
+ = `${ domain } /devrant/ rants` ;
8
11
9
12
export const random
10
13
= `${ rants } /surprise` ;
Original file line number Diff line number Diff line change 1
1
2
- import { users } from './Base.js'
2
+ import { domain , users } from './Base.js'
3
3
4
4
5
+ export const id =
6
+ `${ domain } /get-user-id` ;
7
+
5
8
export const user = ( id ) =>
6
9
`${ users } /${ id } ` ;
7
10
8
- export const edit
9
- = `${ users } /me/edit-profile` ;
11
+ export const edit =
12
+ `${ users } /me/edit-profile` ;
10
13
11
- export const authenticate
12
- = `${ users } /auth-token` ;
14
+ export const authenticate =
15
+ `${ users } /auth-token` ;
13
16
14
- export const notifications
15
- = `${ users } /me/notif-feed` ;
17
+ export const notifications =
18
+ `${ users } /me/notif-feed` ;
16
19
17
- export const avatar
18
- = `${ users } /me/avatar` ;
20
+ export const avatar =
21
+ `${ users } /me/avatar` ;
19
22
20
23
export const subscribe = ( id ) =>
21
24
`${ user ( id ) } /subscribe` ;
File renamed without changes.
Original file line number Diff line number Diff line change
1
+
2
+ const { error , log } = console ;
3
+
4
+
5
+ export async function query ( options ) {
6
+
7
+ let { url , parameters } = options ;
8
+
9
+ url = new URL ( url ) ;
10
+
11
+ parameters ??= { } ;
12
+ parameters . app = 3 ;
13
+
14
+
15
+ const { searchParams } = url ;
16
+
17
+ for ( const [ parameter , value ] of Object . entries ( parameters ) )
18
+ searchParams . set ( parameter , value ) ;
19
+
20
+ log ( url . href ) ;
21
+
22
+ const response = await fetch ( url ) ;
23
+
24
+ log ( response ) ;
25
+
26
+ if ( response . ok )
27
+ return await response . json ( ) ;
28
+
29
+ throw new Error (
30
+ `\n${ response . status } : ${ response . statusText } ` +
31
+ `\nUrl : ${ response . url } `
32
+ )
33
+ }
Original file line number Diff line number Diff line change
1
+
2
+ import { Image } from './Image.ts'
3
+ import { Post } from './Post.ts'
4
+
5
+
6
+ export interface Collaboration extends Post {
7
+
8
+ attached_image : '' | Image ,
9
+
10
+ user_avatar_lg : Avatar ,
11
+
12
+ num_comments : number ,
13
+
14
+ c_type_long : string ,
15
+
16
+ user_dpp : number ,
17
+
18
+ c_type : number ,
19
+
20
+ tags : string [ ] ,
21
+
22
+ text : string ,
23
+
24
+ rt : number ,
25
+
26
+ rc : number ,
27
+
28
+ id : number ,
29
+
30
+ }
Original file line number Diff line number Diff line change 2
2
import { Post } from './Post.ts'
3
3
4
4
5
- export interface Rant extends Post {
5
+ export interface Comment extends Post {
6
6
7
7
body : string
8
8
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { Avatar } from './Avatar.ts'
3
3
import { Link } from './Link.ts'
4
4
5
5
6
- export interface Rant {
6
+ export interface Post {
7
7
8
8
created_time : number ,
9
9
@@ -15,8 +15,6 @@ export interface Rant {
15
15
16
16
user_id : number ,
17
17
18
- edited : bool ,
19
-
20
18
links ? : Link [ ] ,
21
19
22
20
score : number
Original file line number Diff line number Diff line change @@ -5,14 +5,16 @@ import { Post } from './Post.ts'
5
5
6
6
export interface Rant extends Post {
7
7
8
- user_avatar_lg : Avatar ,
9
-
10
8
attached_image : '' | Image ,
11
9
10
+ user_avatar_lg : Avatar ,
11
+
12
12
num_comments : number ,
13
13
14
14
special : bool ,
15
15
16
+ edited : bool ,
17
+
16
18
tags : string [ ] ,
17
19
18
20
text : string ,
@@ -21,6 +23,6 @@ export interface Rant extends Post {
21
23
22
24
rc : number ,
23
25
24
- id : number ,
26
+ id : number
25
27
26
28
}
Original file line number Diff line number Diff line change
1
+
2
+ import { UserContentType } from './UserContentType.ts'
3
+
4
+
5
+ export interface UserContentQuery {
6
+
7
+ content : UserContentType ,
8
+
9
+ userId : string
10
+
11
+ }
Original file line number Diff line number Diff line change 1
1
2
2
export enum UserContentType {
3
3
4
- Collaborations ,
4
+ Collaborations = 'collabs' ,
5
5
6
- Everything ,
6
+ Everything = 'all' ,
7
7
8
- Favorites ,
8
+ Favorites = 'favorites' ,
9
9
10
- Comments ,
10
+ Comments = 'comments' ,
11
11
12
- Rants ,
12
+ Rants = 'rants' ,
13
13
14
- Likes
14
+ Likes = 'likes'
15
15
16
16
}
Original file line number Diff line number Diff line change
1
+
2
+ export * as User from './API/User/mod.ts'
You can’t perform that action at this time.
0 commit comments