Merge pull request #646 from Xyphyn/piefed-3
attempt 3: piefed/general fediverse support
This commit is contained in:
215 files changed
+10368
-325
No files matched your search
@@ -4,7 +4,6 @@
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"htmlWhitespaceSensitivity": "ignore",
|
||||
|
||||
"plugins": ["prettier-plugin-svelte"],
|
||||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||
}
|
||||
@@ -21,7 +21,6 @@ Jump to:
|
||||
<img width="3220" height="1800" alt="Photon dark theme compact" src="https://github.com/user-attachments/assets/76b5278b-e5f9-4c0c-81ec-0820d3261223" />
|
||||
<img width="3220" height="1800" alt="Photon light theme cozy" src="https://github.com/user-attachments/assets/41d205fe-7d32-4b83-bfef-6aa9dd63e074" />
|
||||
|
||||
|
||||
## Self-hosting
|
||||
|
||||
You selfhost a Photon frontend server for your Lemmy instance, or independently for any instance.
|
||||
@@ -39,6 +38,7 @@ To run an unconfigured Photon instance on port `8080`:
|
||||
```sh
|
||||
docker run -p 8080:3000 ghcr.io/xyphyn/photon:latest
|
||||
```
|
||||
|
||||
### Running natively
|
||||
|
||||
Clone the repo:
|
||||
@@ -80,8 +80,11 @@ Photon lets you configure the default client settings and more.
|
||||
If you're hosting Photon for a Lemmy instance, you' ll almost definitely want to set these:
|
||||
|
||||
- `PUBLIC_INSTANCE_URL` `string`: The domain which **the browser** will send API requests to.
|
||||
|
||||
- Example: `PUBLIC_INSTANCE_URL=fedi.phtn.app`
|
||||
|
||||
- `PUBLIC_INSTANCE_TYPE` `lemmyv3 | piefedalpha` (default: `lemmyv3`): If your instance is running Piefed, you must set this option to `piefedalpha`. Otherwise, you don't need to do anything.
|
||||
|
||||
- `PUBLIC_SSR_ENABLED` `boolean`: When enabled, will **make page requests be rendered server side first**, which allows search engine indexing, and basic non-js usage.
|
||||
|
||||
- `PUBLIC_INTERNAL_INSTANCE` `string`: Only relevant if `PUBLIC_SSR_ENABLED=true`. This is the domain that the **server will make API requests to.**
|
||||
|
||||
@@ -29,6 +29,7 @@ export default ts.config(
|
||||
'svelte/prefer-writable-derived': 'off',
|
||||
'no-console': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'svelte/no-navigation-without-resolve': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "photon-lemmy",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.3",
|
||||
"license": "AGPL-3.0-only",
|
||||
"devDependencies": {
|
||||
"@dicebear/core": "^8.0.1",
|
||||
@@ -26,6 +26,7 @@
|
||||
"marked": "7.0.5",
|
||||
"marked-linkify-it": "^3.1.13",
|
||||
"nprogress": "^0.2.0",
|
||||
"openapi-fetch": "^0.14.0",
|
||||
"postcss": "^8.4.30",
|
||||
"prettier": "^3.3.3",
|
||||
"prettier-plugin-svelte": "^3.2.7",
|
||||
|
||||
+13
-9
@@ -5,20 +5,16 @@ import {
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { client, getClient, site } from '$lib/client/lemmy.svelte'
|
||||
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||
import {
|
||||
type Community,
|
||||
type GetSiteResponse,
|
||||
type MyUserInfo,
|
||||
} from 'lemmy-js-client'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { writable } from 'svelte/store'
|
||||
import { t } from './i18n/translations'
|
||||
import { site } from './lemmy.svelte'
|
||||
import { errorMessage } from './lemmy/error'
|
||||
import { publishedToDate } from './components/util/date'
|
||||
import type { Community, GetSiteResponse, MyUserInfo } from './client/types'
|
||||
import { DEFAULT_CLIENT_TYPE, type ClientType } from './client/base'
|
||||
|
||||
function getFromStorage<T>(key: string): T | undefined {
|
||||
if (typeof localStorage == 'undefined') return undefined
|
||||
@@ -42,6 +38,7 @@ export interface ProfileInfo {
|
||||
avatar?: string
|
||||
favorites?: Community[]
|
||||
color?: string
|
||||
client: ClientType
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +75,7 @@ class Profile {
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
username: 'Guest',
|
||||
color: '#505050',
|
||||
client: DEFAULT_CLIENT_TYPE,
|
||||
},
|
||||
],
|
||||
profile: 1,
|
||||
@@ -92,6 +90,7 @@ class Profile {
|
||||
return {
|
||||
id: -1,
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
client: DEFAULT_CLIENT_TYPE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +104,11 @@ class Profile {
|
||||
const jwt = getCookie('jwt')
|
||||
if (jwt) {
|
||||
;(async () => {
|
||||
const result = await this.add(jwt, env.PUBLIC_INSTANCE_URL ?? '')
|
||||
const result = await this.add(
|
||||
jwt,
|
||||
env.PUBLIC_INSTANCE_URL ?? '',
|
||||
DEFAULT_CLIENT_TYPE,
|
||||
)
|
||||
|
||||
if (result)
|
||||
toast({
|
||||
@@ -221,7 +224,7 @@ class Profile {
|
||||
}
|
||||
}
|
||||
|
||||
async add(jwt: string, instance: string) {
|
||||
async add(jwt: string, instance: string, type: ClientType) {
|
||||
const user = await userFromJwt(jwt, instance)
|
||||
.then(u => u)
|
||||
.catch(err => {
|
||||
@@ -242,6 +245,7 @@ class Profile {
|
||||
jwt: jwt,
|
||||
username: user?.user?.local_user_view.person.name,
|
||||
avatar: user?.user?.local_user_view.person.avatar,
|
||||
client: type,
|
||||
})
|
||||
|
||||
return user
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
import { env } from '$env/dynamic/public'
|
||||
import * as types from './types'
|
||||
|
||||
export type ClientType =
|
||||
| { name: 'lemmy'; baseUrl: '/api/v3' }
|
||||
| { name: 'piefed'; baseUrl: '/api/alpha' }
|
||||
|
||||
export const DEFAULT_CLIENT_TYPE: ClientType =
|
||||
env.PUBLIC_INSTANCE_TYPE == 'piefedalpha'
|
||||
? {
|
||||
name: 'piefed',
|
||||
baseUrl: '/api/alpha',
|
||||
}
|
||||
: {
|
||||
name: 'lemmy',
|
||||
baseUrl: '/api/v3',
|
||||
}
|
||||
|
||||
export abstract class BaseClient {
|
||||
abstract type: ClientType
|
||||
|
||||
abstract getSite(): Promise<types.GetSiteResponse>
|
||||
abstract generateTotpSecret(): Promise<types.GenerateTotpSecretResponse>
|
||||
abstract listLogins(): Promise<types.LoginToken[]>
|
||||
abstract listAllMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
|
||||
abstract updateTotp(form: types.UpdateTotp): Promise<types.UpdateTotpResponse>
|
||||
abstract getModlog(form: types.GetModlog): Promise<types.GetModlogResponse>
|
||||
abstract search(form: types.Search): Promise<types.SearchResponse>
|
||||
abstract resolveObject(
|
||||
form: types.ResolveObject,
|
||||
): Promise<types.ResolveObjectResponse>
|
||||
abstract createCommunity(
|
||||
form: types.CreateCommunity,
|
||||
): Promise<types.CommunityResponse>
|
||||
abstract getCommunity(
|
||||
form: types.GetCommunity,
|
||||
): Promise<types.GetCommunityResponse>
|
||||
abstract editCommunity(
|
||||
form: types.EditCommunity,
|
||||
): Promise<types.CommunityResponse>
|
||||
abstract listCommunities(
|
||||
form: types.ListCommunities,
|
||||
): Promise<types.ListCommunitiesResponse>
|
||||
abstract followCommunity(
|
||||
form: types.FollowCommunity,
|
||||
): Promise<types.CommunityResponse>
|
||||
abstract blockCommunity(
|
||||
form: types.BlockCommunity,
|
||||
): Promise<types.BlockCommunityResponse>
|
||||
abstract deleteCommunity(
|
||||
form: types.DeleteCommunity,
|
||||
): Promise<types.CommunityResponse>
|
||||
abstract hideCommunity(
|
||||
form: types.HideCommunity,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract removeCommunity(
|
||||
form: types.RemoveCommunity,
|
||||
): Promise<types.CommunityResponse>
|
||||
abstract banFromCommunity(
|
||||
form: types.BanFromCommunity,
|
||||
): Promise<types.BanFromCommunityResponse>
|
||||
abstract addModToCommunity(
|
||||
form: types.AddModToCommunity,
|
||||
): Promise<types.AddModToCommunityResponse>
|
||||
abstract createPost(form: types.CreatePost): Promise<types.PostResponse>
|
||||
abstract getPost(form: types.GetPost): Promise<types.GetPostResponse>
|
||||
abstract editPost(form: types.EditPost): Promise<types.PostResponse>
|
||||
abstract deletePost(form: types.DeletePost): Promise<types.PostResponse>
|
||||
abstract removePost(form: types.RemovePost): Promise<types.PostResponse>
|
||||
abstract markPostAsRead(
|
||||
form: types.MarkPostAsRead,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract hidePost(form: types.HidePost): Promise<types.SuccessResponse>
|
||||
abstract lockPost(form: types.LockPost): Promise<types.PostResponse>
|
||||
abstract featurePost(form: types.FeaturePost): Promise<types.PostResponse>
|
||||
abstract getPosts(form: types.GetPosts): Promise<types.GetPostsResponse>
|
||||
abstract likePost(form: types.CreatePostLike): Promise<types.PostResponse>
|
||||
abstract listPostLikes(
|
||||
form: types.ListPostLikes,
|
||||
): Promise<types.ListPostLikesResponse>
|
||||
abstract savePost(form: types.SavePost): Promise<types.PostResponse>
|
||||
// TODO should unify these reports probably
|
||||
abstract createPostReport(
|
||||
form: types.CreatePostReport,
|
||||
): Promise<types.PostReportResponse>
|
||||
abstract resolvePostReport(
|
||||
form: types.ResolvePostReport,
|
||||
): Promise<types.PostReportResponse>
|
||||
abstract listPostReports(
|
||||
form: types.ListPostReports,
|
||||
): Promise<types.ListPostReportsResponse>
|
||||
abstract getSiteMetadata(
|
||||
form: types.GetSiteMetadata,
|
||||
): Promise<types.GetSiteMetadataResponse>
|
||||
abstract createComment(
|
||||
form: types.CreateComment,
|
||||
): Promise<types.CommentResponse>
|
||||
abstract editComment(form: types.EditComment): Promise<types.CommentResponse>
|
||||
abstract deleteComment(
|
||||
form: types.DeleteComment,
|
||||
): Promise<types.CommentResponse>
|
||||
abstract removeComment(
|
||||
form: types.RemoveComment,
|
||||
): Promise<types.CommentResponse>
|
||||
abstract markCommentReplyAsRead(
|
||||
form: types.MarkCommentReplyAsRead,
|
||||
): Promise<types.CommentReplyResponse | void>
|
||||
abstract likeComment(
|
||||
form: types.CreateCommentLike,
|
||||
): Promise<types.CommentResponse>
|
||||
abstract listCommentLikes(
|
||||
form: types.ListCommentLikes,
|
||||
): Promise<types.ListCommentLikesResponse>
|
||||
// TODO unify saving with posts too
|
||||
// i have options for unifying these since I'm making the API client myself now
|
||||
abstract saveComment(form: types.SaveComment): Promise<types.CommentResponse>
|
||||
abstract distinguishComment(
|
||||
form: types.DistinguishComment,
|
||||
): Promise<types.CommentResponse>
|
||||
abstract getComments(
|
||||
form: types.GetComments,
|
||||
): Promise<types.GetCommentsResponse>
|
||||
abstract getComment(form: types.GetComment): Promise<types.CommentResponse>
|
||||
abstract createCommentReport(
|
||||
form: types.CreateCommentReport,
|
||||
): Promise<types.CommentReportResponse>
|
||||
abstract resolveCommentReport(
|
||||
form: types.ResolveCommentReport,
|
||||
): Promise<types.CommentReportResponse>
|
||||
abstract listCommentReports(
|
||||
form: types.ListCommentReports,
|
||||
): Promise<types.ListCommentReportsResponse>
|
||||
abstract getPrivateMessages(
|
||||
form: types.GetPrivateMessages,
|
||||
): Promise<types.PrivateMessagesResponse>
|
||||
abstract createPrivateMessage(
|
||||
form: types.CreatePrivateMessage,
|
||||
): Promise<types.PrivateMessageResponse>
|
||||
abstract editPrivateMessage(
|
||||
form: types.EditPrivateMessage,
|
||||
): Promise<types.PrivateMessageResponse>
|
||||
abstract deletePrivateMessage(
|
||||
form: types.DeletePrivateMessage,
|
||||
): Promise<types.PrivateMessageResponse>
|
||||
abstract markPrivateMessageAsRead(
|
||||
form: types.MarkPrivateMessageAsRead,
|
||||
): Promise<types.PrivateMessageResponse>
|
||||
abstract createPrivateMessageReport(
|
||||
form: types.CreatePrivateMessageReport,
|
||||
): Promise<types.PrivateMessageReportResponse>
|
||||
abstract resolvePrivateMessageReport(
|
||||
form: types.ResolvePrivateMessageReport,
|
||||
): Promise<types.PrivateMessageReportResponse>
|
||||
abstract listPrivateMessageReports(
|
||||
form: types.ListPrivateMessageReports,
|
||||
): Promise<types.ListPrivateMessageReportsResponse>
|
||||
abstract register(form: types.Register): Promise<types.LoginResponse>
|
||||
abstract login(form: types.Login): Promise<types.LoginResponse>
|
||||
abstract logout(): Promise<types.SuccessResponse>
|
||||
abstract getPersonDetails(
|
||||
form: types.GetPersonDetails,
|
||||
): Promise<types.GetPersonDetailsResponse>
|
||||
// TODO unify these inbox things too
|
||||
abstract getPersonMentions(
|
||||
form: types.GetPersonMentions,
|
||||
): Promise<types.GetPersonMentionsResponse>
|
||||
abstract markPersonMentionAsRead(
|
||||
form: types.MarkPersonMentionAsRead,
|
||||
): Promise<types.PersonMentionResponse | void>
|
||||
abstract getReplies(form: types.GetReplies): Promise<types.GetRepliesResponse>
|
||||
abstract banPerson(form: types.BanPerson): Promise<types.BanPersonResponse>
|
||||
abstract getBannedPersons(): Promise<types.BannedPersonsResponse>
|
||||
abstract blockPerson(
|
||||
form: types.BlockPerson,
|
||||
): Promise<types.BlockPersonResponse>
|
||||
abstract getCaptcha(): Promise<types.GetCaptchaResponse>
|
||||
abstract deleteAccount(
|
||||
form: types.DeleteAccount,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract passwordReset(
|
||||
form: types.PasswordReset,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract passwordChangeAfterReset(
|
||||
form: types.PasswordChangeAfterReset,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract markAllAsRead(): Promise<types.GetRepliesResponse>
|
||||
abstract saveUserSettings(
|
||||
form: types.SaveUserSettings,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract changePassword(
|
||||
form: types.ChangePassword,
|
||||
): Promise<types.LoginResponse>
|
||||
abstract getReportCount(
|
||||
form: types.GetReportCount,
|
||||
): Promise<types.GetReportCountResponse>
|
||||
abstract getUnreadCount(): Promise<types.GetUnreadCountResponse>
|
||||
abstract verifyEmail(form: types.VerifyEmail): Promise<types.SuccessResponse>
|
||||
abstract addAdmin(form: types.AddAdmin): Promise<types.AddAdminResponse>
|
||||
abstract getUnreadRegistrationApplicationCount(): Promise<types.GetUnreadRegistrationApplicationCountResponse>
|
||||
abstract listRegistrationApplications(
|
||||
form: types.ListRegistrationApplications,
|
||||
): Promise<types.ListRegistrationApplicationsResponse>
|
||||
abstract approveRegistrationApplication(
|
||||
form: types.ApproveRegistrationApplication,
|
||||
): Promise<types.RegistrationApplicationResponse>
|
||||
abstract getRegistrationApplication(
|
||||
form: types.GetRegistrationApplication,
|
||||
): Promise<types.RegistrationApplicationResponse>
|
||||
abstract purgePerson(form: types.PurgePerson): Promise<types.SuccessResponse>
|
||||
abstract purgeCommunity(
|
||||
form: types.PurgeCommunity,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract purgePost(form: types.PurgePost): Promise<types.SuccessResponse>
|
||||
abstract purgeComment(
|
||||
form: types.PurgeComment,
|
||||
): Promise<types.SuccessResponse>
|
||||
abstract getFederatedInstances(): Promise<types.GetFederatedInstancesResponse>
|
||||
abstract blockInstance(
|
||||
form: types.BlockInstance,
|
||||
): Promise<types.BlockInstanceResponse>
|
||||
abstract uploadImage(
|
||||
form: types.UploadImage,
|
||||
): Promise<types.UploadImageResponse>
|
||||
|
||||
abstract setFlair?(form: types.SetPersonFlair): Promise<types.PersonView>
|
||||
}
|
||||
|
||||
export type NullableFnArg<T, Fallback = never> = T extends (
|
||||
...args: infer A
|
||||
) => any
|
||||
? A
|
||||
: Fallback
|
||||
|
||||
export type NullableFnReturn<T, Fallback = never> = T extends (
|
||||
...args: any[]
|
||||
) => infer A
|
||||
? A
|
||||
: Fallback
|
||||
@@ -2,7 +2,10 @@ import { profile } from '$lib/auth.svelte'
|
||||
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { LemmyHttp, type GetSiteResponse } from 'lemmy-js-client'
|
||||
import { type GetSiteResponse } from '$lib/client/types'
|
||||
import { LemmyClient } from './lemmy/lemmy'
|
||||
import { PiefedClient } from './piefed/piefed'
|
||||
import { DEFAULT_CLIENT_TYPE, type ClientType, BaseClient } from './base'
|
||||
|
||||
class SiteData {
|
||||
#data = $state<GetSiteResponse>()
|
||||
@@ -52,6 +55,7 @@ export function client({
|
||||
instanceURL,
|
||||
func,
|
||||
auth,
|
||||
clientType,
|
||||
}: {
|
||||
instanceURL?: string
|
||||
func?: (
|
||||
@@ -59,22 +63,30 @@ export function client({
|
||||
init?: RequestInit | undefined,
|
||||
) => Promise<Response>
|
||||
auth?: string
|
||||
} = {}) {
|
||||
clientType?: ClientType
|
||||
} = {}): BaseClient {
|
||||
if (!instanceURL)
|
||||
instanceURL = profile.current.instance || DEFAULT_INSTANCE_URL
|
||||
|
||||
if (!clientType) {
|
||||
clientType = profile.current.client ?? DEFAULT_CLIENT_TYPE
|
||||
}
|
||||
|
||||
// we use nullish coealsiaihsa something so that
|
||||
// we can set auth = '' to remove it
|
||||
|
||||
const jwt = auth ?? profile.current?.jwt
|
||||
|
||||
// but not here, so that if jwt == '', it doesnt put a bearer
|
||||
const headers = jwt ? { authorization: `Bearer ${jwt}` } : {}
|
||||
|
||||
return new LemmyHttp(instanceToURL(instanceURL), {
|
||||
fetchFunction: (input, init) => customFetch(func, input, init, jwt),
|
||||
// @ts-expect-error headers thing
|
||||
headers: headers,
|
||||
})
|
||||
return new (clientType.name == 'piefed' ? PiefedClient : LemmyClient)(
|
||||
instanceToURL(instanceURL),
|
||||
{
|
||||
fetchFunction: (input, init) => customFetch(func, input, init, jwt),
|
||||
headers: headers,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// here for parts where i forgor to switch
|
||||
@@ -85,49 +97,25 @@ export function getClient(
|
||||
init?: RequestInit | undefined,
|
||||
) => Promise<Response>,
|
||||
auth?: string,
|
||||
): LemmyHttp {
|
||||
) {
|
||||
return client({ instanceURL, func, auth })
|
||||
}
|
||||
|
||||
export async function validateInstance(instance: string): Promise<boolean> {
|
||||
export async function validateInstance(
|
||||
instance: string,
|
||||
type: ClientType,
|
||||
): Promise<boolean> {
|
||||
if (instance == '') return false
|
||||
|
||||
try {
|
||||
await client({ instanceURL: instance, auth: '' }).getSite()
|
||||
await client({
|
||||
instanceURL: instance,
|
||||
clientType: type,
|
||||
auth: '',
|
||||
}).getSite()
|
||||
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function mayBeIncompatible(
|
||||
minVersion: string,
|
||||
availableVersion: string,
|
||||
) {
|
||||
if (minVersion.valueOf() === availableVersion.valueOf()) return false
|
||||
|
||||
const versionFormatter = /[\d.]/
|
||||
if (
|
||||
!minVersion.match(versionFormatter) ||
|
||||
!availableVersion.match(availableVersion)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
const splitMinVersion = minVersion.split('.')
|
||||
const splitAvailableVersion = availableVersion.split('.')
|
||||
|
||||
if (splitMinVersion.length !== splitAvailableVersion.length) return true
|
||||
|
||||
for (let i = 0; i < splitMinVersion.length; ++i) {
|
||||
const minVersionDigit = parseInt(splitMinVersion[i])
|
||||
const availableVersionDigit = parseInt(splitAvailableVersion[i])
|
||||
|
||||
if (availableVersionDigit === undefined) return true
|
||||
if (minVersionDigit < availableVersionDigit) return false
|
||||
if (availableVersionDigit < minVersionDigit) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,479 @@
|
||||
import { LemmyHttp } from 'lemmy-js-client'
|
||||
import type { BaseClient, ClientType } from '../base'
|
||||
import { fromGetPosts, toListingType } from './rewrite'
|
||||
|
||||
export class LemmyClient implements BaseClient {
|
||||
type: ClientType = { name: 'lemmy', baseUrl: '/api/v3' }
|
||||
|
||||
#client: LemmyHttp
|
||||
|
||||
constructor(
|
||||
baseUrl: string,
|
||||
args: {
|
||||
fetchFunction: (input: any, init: any) => Promise<any>
|
||||
headers: any
|
||||
},
|
||||
) {
|
||||
this.#client = new LemmyHttp(baseUrl, args)
|
||||
}
|
||||
|
||||
async getSite(
|
||||
...params: Parameters<BaseClient['getSite']>
|
||||
): ReturnType<BaseClient['getSite']> {
|
||||
return await this.#client.getSite(...params)
|
||||
}
|
||||
async generateTotpSecret(
|
||||
...params: Parameters<BaseClient['generateTotpSecret']>
|
||||
): ReturnType<BaseClient['generateTotpSecret']> {
|
||||
return await this.#client.generateTotpSecret(...params)
|
||||
}
|
||||
async listLogins(
|
||||
...params: Parameters<BaseClient['listLogins']>
|
||||
): ReturnType<BaseClient['listLogins']> {
|
||||
return await this.#client.listLogins(...params)
|
||||
}
|
||||
async listAllMedia(
|
||||
...params: Parameters<BaseClient['listAllMedia']>
|
||||
): ReturnType<BaseClient['listAllMedia']> {
|
||||
return await this.#client.listAllMedia(...params)
|
||||
}
|
||||
async updateTotp(
|
||||
...params: Parameters<BaseClient['updateTotp']>
|
||||
): ReturnType<BaseClient['updateTotp']> {
|
||||
return await this.#client.updateTotp(...params)
|
||||
}
|
||||
async getModlog(
|
||||
...params: Parameters<BaseClient['getModlog']>
|
||||
): ReturnType<BaseClient['getModlog']> {
|
||||
return await this.#client.getModlog(...params)
|
||||
}
|
||||
async search(
|
||||
params: Parameters<BaseClient['search']>[0],
|
||||
): ReturnType<BaseClient['search']> {
|
||||
return await this.#client.search({
|
||||
...params,
|
||||
listing_type: toListingType(params.listing_type),
|
||||
})
|
||||
}
|
||||
async resolveObject(
|
||||
...params: Parameters<BaseClient['resolveObject']>
|
||||
): ReturnType<BaseClient['resolveObject']> {
|
||||
return await this.#client.resolveObject(...params)
|
||||
}
|
||||
async createCommunity(
|
||||
...params: Parameters<BaseClient['createCommunity']>
|
||||
): ReturnType<BaseClient['createCommunity']> {
|
||||
return await this.#client.createCommunity(...params)
|
||||
}
|
||||
async getCommunity(
|
||||
...params: Parameters<BaseClient['getCommunity']>
|
||||
): ReturnType<BaseClient['getCommunity']> {
|
||||
return await this.#client.getCommunity(...params)
|
||||
}
|
||||
async editCommunity(
|
||||
...params: Parameters<BaseClient['editCommunity']>
|
||||
): ReturnType<BaseClient['editCommunity']> {
|
||||
return await this.#client.editCommunity(...params)
|
||||
}
|
||||
async listCommunities(
|
||||
params: Parameters<BaseClient['listCommunities']>[0],
|
||||
): ReturnType<BaseClient['listCommunities']> {
|
||||
return await this.#client.listCommunities({
|
||||
...params,
|
||||
type_: toListingType(params.type_),
|
||||
})
|
||||
}
|
||||
async followCommunity(
|
||||
...params: Parameters<BaseClient['followCommunity']>
|
||||
): ReturnType<BaseClient['followCommunity']> {
|
||||
return await this.#client.followCommunity(...params)
|
||||
}
|
||||
async blockCommunity(
|
||||
...params: Parameters<BaseClient['blockCommunity']>
|
||||
): ReturnType<BaseClient['blockCommunity']> {
|
||||
return await this.#client.blockCommunity(...params)
|
||||
}
|
||||
async deleteCommunity(
|
||||
...params: Parameters<BaseClient['deleteCommunity']>
|
||||
): ReturnType<BaseClient['deleteCommunity']> {
|
||||
return await this.#client.deleteCommunity(...params)
|
||||
}
|
||||
async hideCommunity(
|
||||
...params: Parameters<BaseClient['hideCommunity']>
|
||||
): ReturnType<BaseClient['hideCommunity']> {
|
||||
return await this.#client.hideCommunity(...params)
|
||||
}
|
||||
async removeCommunity(
|
||||
...params: Parameters<BaseClient['removeCommunity']>
|
||||
): ReturnType<BaseClient['removeCommunity']> {
|
||||
return await this.#client.removeCommunity(...params)
|
||||
}
|
||||
async banFromCommunity(
|
||||
...params: Parameters<BaseClient['banFromCommunity']>
|
||||
): ReturnType<BaseClient['banFromCommunity']> {
|
||||
return await this.#client.banFromCommunity(...params)
|
||||
}
|
||||
async addModToCommunity(
|
||||
...params: Parameters<BaseClient['addModToCommunity']>
|
||||
): ReturnType<BaseClient['addModToCommunity']> {
|
||||
return await this.#client.addModToCommunity(...params)
|
||||
}
|
||||
async createPost(
|
||||
...params: Parameters<BaseClient['createPost']>
|
||||
): ReturnType<BaseClient['createPost']> {
|
||||
return await this.#client.createPost(...params)
|
||||
}
|
||||
async getPost(
|
||||
...params: Parameters<BaseClient['getPost']>
|
||||
): ReturnType<BaseClient['getPost']> {
|
||||
return await this.#client.getPost(...params)
|
||||
}
|
||||
async editPost(
|
||||
...params: Parameters<BaseClient['editPost']>
|
||||
): ReturnType<BaseClient['editPost']> {
|
||||
return await this.#client.editPost(...params)
|
||||
}
|
||||
async deletePost(
|
||||
...params: Parameters<BaseClient['deletePost']>
|
||||
): ReturnType<BaseClient['deletePost']> {
|
||||
return await this.#client.deletePost(...params)
|
||||
}
|
||||
async removePost(
|
||||
...params: Parameters<BaseClient['removePost']>
|
||||
): ReturnType<BaseClient['removePost']> {
|
||||
return await this.#client.removePost(...params)
|
||||
}
|
||||
async markPostAsRead(
|
||||
...params: Parameters<BaseClient['markPostAsRead']>
|
||||
): ReturnType<BaseClient['markPostAsRead']> {
|
||||
return await this.#client.markPostAsRead(...params)
|
||||
}
|
||||
async hidePost(
|
||||
...params: Parameters<BaseClient['hidePost']>
|
||||
): ReturnType<BaseClient['hidePost']> {
|
||||
return await this.#client.hidePost(...params)
|
||||
}
|
||||
async lockPost(
|
||||
...params: Parameters<BaseClient['lockPost']>
|
||||
): ReturnType<BaseClient['lockPost']> {
|
||||
return await this.#client.lockPost(...params)
|
||||
}
|
||||
async featurePost(
|
||||
...params: Parameters<BaseClient['featurePost']>
|
||||
): ReturnType<BaseClient['featurePost']> {
|
||||
return await this.#client.featurePost(...params)
|
||||
}
|
||||
async getPosts(
|
||||
params: Parameters<BaseClient['getPosts']>[0],
|
||||
): ReturnType<BaseClient['getPosts']> {
|
||||
return await this.#client.getPosts(fromGetPosts(params))
|
||||
}
|
||||
async likePost(
|
||||
...params: Parameters<BaseClient['likePost']>
|
||||
): ReturnType<BaseClient['likePost']> {
|
||||
return await this.#client.likePost(...params)
|
||||
}
|
||||
async listPostLikes(
|
||||
...params: Parameters<BaseClient['listPostLikes']>
|
||||
): ReturnType<BaseClient['listPostLikes']> {
|
||||
return await this.#client.listPostLikes(...params)
|
||||
}
|
||||
async savePost(
|
||||
...params: Parameters<BaseClient['savePost']>
|
||||
): ReturnType<BaseClient['savePost']> {
|
||||
return await this.#client.savePost(...params)
|
||||
}
|
||||
async createPostReport(
|
||||
...params: Parameters<BaseClient['createPostReport']>
|
||||
): ReturnType<BaseClient['createPostReport']> {
|
||||
return await this.#client.createPostReport(...params)
|
||||
}
|
||||
async resolvePostReport(
|
||||
...params: Parameters<BaseClient['resolvePostReport']>
|
||||
): ReturnType<BaseClient['resolvePostReport']> {
|
||||
return await this.#client.resolvePostReport(...params)
|
||||
}
|
||||
async listPostReports(
|
||||
...params: Parameters<BaseClient['listPostReports']>
|
||||
): ReturnType<BaseClient['listPostReports']> {
|
||||
return await this.#client.listPostReports(...params)
|
||||
}
|
||||
async getSiteMetadata(
|
||||
...params: Parameters<BaseClient['getSiteMetadata']>
|
||||
): ReturnType<BaseClient['getSiteMetadata']> {
|
||||
return await this.#client.getSiteMetadata(...params)
|
||||
}
|
||||
async createComment(
|
||||
...params: Parameters<BaseClient['createComment']>
|
||||
): ReturnType<BaseClient['createComment']> {
|
||||
return await this.#client.createComment(...params)
|
||||
}
|
||||
async editComment(
|
||||
...params: Parameters<BaseClient['editComment']>
|
||||
): ReturnType<BaseClient['editComment']> {
|
||||
return await this.#client.editComment(...params)
|
||||
}
|
||||
async deleteComment(
|
||||
...params: Parameters<BaseClient['deleteComment']>
|
||||
): ReturnType<BaseClient['deleteComment']> {
|
||||
return await this.#client.deleteComment(...params)
|
||||
}
|
||||
async removeComment(
|
||||
...params: Parameters<BaseClient['removeComment']>
|
||||
): ReturnType<BaseClient['removeComment']> {
|
||||
return await this.#client.removeComment(...params)
|
||||
}
|
||||
async markCommentReplyAsRead(
|
||||
...params: Parameters<BaseClient['markCommentReplyAsRead']>
|
||||
): ReturnType<BaseClient['markCommentReplyAsRead']> {
|
||||
return await this.#client.markCommentReplyAsRead(...params)
|
||||
}
|
||||
async likeComment(
|
||||
...params: Parameters<BaseClient['likeComment']>
|
||||
): ReturnType<BaseClient['likeComment']> {
|
||||
return await this.#client.likeComment(...params)
|
||||
}
|
||||
async listCommentLikes(
|
||||
...params: Parameters<BaseClient['listCommentLikes']>
|
||||
): ReturnType<BaseClient['listCommentLikes']> {
|
||||
return await this.#client.listCommentLikes(...params)
|
||||
}
|
||||
async saveComment(
|
||||
...params: Parameters<BaseClient['saveComment']>
|
||||
): ReturnType<BaseClient['saveComment']> {
|
||||
return await this.#client.saveComment(...params)
|
||||
}
|
||||
async distinguishComment(
|
||||
...params: Parameters<BaseClient['distinguishComment']>
|
||||
): ReturnType<BaseClient['distinguishComment']> {
|
||||
return await this.#client.distinguishComment(...params)
|
||||
}
|
||||
async getComments(
|
||||
params: Parameters<BaseClient['getComments']>[0],
|
||||
): ReturnType<BaseClient['getComments']> {
|
||||
return await this.#client.getComments({
|
||||
...params,
|
||||
type_: toListingType(params.type_),
|
||||
})
|
||||
}
|
||||
async getComment(
|
||||
...params: Parameters<BaseClient['getComment']>
|
||||
): ReturnType<BaseClient['getComment']> {
|
||||
return await this.#client.getComment(...params)
|
||||
}
|
||||
async createCommentReport(
|
||||
...params: Parameters<BaseClient['createCommentReport']>
|
||||
): ReturnType<BaseClient['createCommentReport']> {
|
||||
return await this.#client.createCommentReport(...params)
|
||||
}
|
||||
async resolveCommentReport(
|
||||
...params: Parameters<BaseClient['resolveCommentReport']>
|
||||
): ReturnType<BaseClient['resolveCommentReport']> {
|
||||
return await this.#client.resolveCommentReport(...params)
|
||||
}
|
||||
async listCommentReports(
|
||||
...params: Parameters<BaseClient['listCommentReports']>
|
||||
): ReturnType<BaseClient['listCommentReports']> {
|
||||
return await this.#client.listCommentReports(...params)
|
||||
}
|
||||
async getPrivateMessages(
|
||||
...params: Parameters<BaseClient['getPrivateMessages']>
|
||||
): ReturnType<BaseClient['getPrivateMessages']> {
|
||||
return await this.#client.getPrivateMessages(...params)
|
||||
}
|
||||
async createPrivateMessage(
|
||||
...params: Parameters<BaseClient['createPrivateMessage']>
|
||||
): ReturnType<BaseClient['createPrivateMessage']> {
|
||||
return await this.#client.createPrivateMessage(...params)
|
||||
}
|
||||
async editPrivateMessage(
|
||||
...params: Parameters<BaseClient['editPrivateMessage']>
|
||||
): ReturnType<BaseClient['editPrivateMessage']> {
|
||||
return await this.#client.editPrivateMessage(...params)
|
||||
}
|
||||
async deletePrivateMessage(
|
||||
...params: Parameters<BaseClient['deletePrivateMessage']>
|
||||
): ReturnType<BaseClient['deletePrivateMessage']> {
|
||||
return await this.#client.deletePrivateMessage(...params)
|
||||
}
|
||||
async markPrivateMessageAsRead(
|
||||
...params: Parameters<BaseClient['markPrivateMessageAsRead']>
|
||||
): ReturnType<BaseClient['markPrivateMessageAsRead']> {
|
||||
return await this.#client.markPrivateMessageAsRead(...params)
|
||||
}
|
||||
async createPrivateMessageReport(
|
||||
...params: Parameters<BaseClient['createPrivateMessageReport']>
|
||||
): ReturnType<BaseClient['createPrivateMessageReport']> {
|
||||
return await this.#client.createPrivateMessageReport(...params)
|
||||
}
|
||||
async resolvePrivateMessageReport(
|
||||
...params: Parameters<BaseClient['resolvePrivateMessageReport']>
|
||||
): ReturnType<BaseClient['resolvePrivateMessageReport']> {
|
||||
return await this.#client.resolvePrivateMessageReport(...params)
|
||||
}
|
||||
async listPrivateMessageReports(
|
||||
...params: Parameters<BaseClient['listPrivateMessageReports']>
|
||||
): ReturnType<BaseClient['listPrivateMessageReports']> {
|
||||
return await this.#client.listPrivateMessageReports(...params)
|
||||
}
|
||||
async register(
|
||||
...params: Parameters<BaseClient['register']>
|
||||
): ReturnType<BaseClient['register']> {
|
||||
return await this.#client.register(...params)
|
||||
}
|
||||
async login(
|
||||
...params: Parameters<BaseClient['login']>
|
||||
): ReturnType<BaseClient['login']> {
|
||||
return await this.#client.login(...params)
|
||||
}
|
||||
async logout(
|
||||
...params: Parameters<BaseClient['logout']>
|
||||
): ReturnType<BaseClient['logout']> {
|
||||
return await this.#client.logout(...params)
|
||||
}
|
||||
async getPersonDetails(
|
||||
...params: Parameters<BaseClient['getPersonDetails']>
|
||||
): ReturnType<BaseClient['getPersonDetails']> {
|
||||
return await this.#client.getPersonDetails(...params)
|
||||
}
|
||||
async getPersonMentions(
|
||||
...params: Parameters<BaseClient['getPersonMentions']>
|
||||
): ReturnType<BaseClient['getPersonMentions']> {
|
||||
return await this.#client.getPersonMentions(...params)
|
||||
}
|
||||
async markPersonMentionAsRead(
|
||||
...params: Parameters<BaseClient['markPersonMentionAsRead']>
|
||||
): ReturnType<BaseClient['markPersonMentionAsRead']> {
|
||||
return await this.#client.markPersonMentionAsRead(...params)
|
||||
}
|
||||
async getReplies(
|
||||
...params: Parameters<BaseClient['getReplies']>
|
||||
): ReturnType<BaseClient['getReplies']> {
|
||||
return await this.#client.getReplies(...params)
|
||||
}
|
||||
async banPerson(
|
||||
...params: Parameters<BaseClient['banPerson']>
|
||||
): ReturnType<BaseClient['banPerson']> {
|
||||
return await this.#client.banPerson(...params)
|
||||
}
|
||||
async getBannedPersons(
|
||||
...params: Parameters<BaseClient['getBannedPersons']>
|
||||
): ReturnType<BaseClient['getBannedPersons']> {
|
||||
return await this.#client.getBannedPersons(...params)
|
||||
}
|
||||
async blockPerson(
|
||||
...params: Parameters<BaseClient['blockPerson']>
|
||||
): ReturnType<BaseClient['blockPerson']> {
|
||||
return await this.#client.blockPerson(...params)
|
||||
}
|
||||
async getCaptcha(
|
||||
...params: Parameters<BaseClient['getCaptcha']>
|
||||
): ReturnType<BaseClient['getCaptcha']> {
|
||||
return await this.#client.getCaptcha(...params)
|
||||
}
|
||||
async deleteAccount(
|
||||
...params: Parameters<BaseClient['deleteAccount']>
|
||||
): ReturnType<BaseClient['deleteAccount']> {
|
||||
return await this.#client.deleteAccount(...params)
|
||||
}
|
||||
async passwordReset(
|
||||
...params: Parameters<BaseClient['passwordReset']>
|
||||
): ReturnType<BaseClient['passwordReset']> {
|
||||
return await this.#client.passwordReset(...params)
|
||||
}
|
||||
async passwordChangeAfterReset(
|
||||
...params: Parameters<BaseClient['passwordChangeAfterReset']>
|
||||
): ReturnType<BaseClient['passwordChangeAfterReset']> {
|
||||
return await this.#client.passwordChangeAfterReset(...params)
|
||||
}
|
||||
async markAllAsRead(
|
||||
...params: Parameters<BaseClient['markAllAsRead']>
|
||||
): ReturnType<BaseClient['markAllAsRead']> {
|
||||
return await this.#client.markAllAsRead(...params)
|
||||
}
|
||||
async saveUserSettings(
|
||||
...params: Parameters<BaseClient['saveUserSettings']>
|
||||
): ReturnType<BaseClient['saveUserSettings']> {
|
||||
return await this.#client.saveUserSettings(...params)
|
||||
}
|
||||
async changePassword(
|
||||
...params: Parameters<BaseClient['changePassword']>
|
||||
): ReturnType<BaseClient['changePassword']> {
|
||||
return await this.#client.changePassword(...params)
|
||||
}
|
||||
async getReportCount(
|
||||
...params: Parameters<BaseClient['getReportCount']>
|
||||
): ReturnType<BaseClient['getReportCount']> {
|
||||
return await this.#client.getReportCount(...params)
|
||||
}
|
||||
async getUnreadCount(
|
||||
...params: Parameters<BaseClient['getUnreadCount']>
|
||||
): ReturnType<BaseClient['getUnreadCount']> {
|
||||
return await this.#client.getUnreadCount(...params)
|
||||
}
|
||||
async verifyEmail(
|
||||
...params: Parameters<BaseClient['verifyEmail']>
|
||||
): ReturnType<BaseClient['verifyEmail']> {
|
||||
return await this.#client.verifyEmail(...params)
|
||||
}
|
||||
async addAdmin(
|
||||
...params: Parameters<BaseClient['addAdmin']>
|
||||
): ReturnType<BaseClient['addAdmin']> {
|
||||
return await this.#client.addAdmin(...params)
|
||||
}
|
||||
async getUnreadRegistrationApplicationCount(
|
||||
...params: Parameters<BaseClient['getUnreadRegistrationApplicationCount']>
|
||||
): ReturnType<BaseClient['getUnreadRegistrationApplicationCount']> {
|
||||
return await this.#client.getUnreadRegistrationApplicationCount(...params)
|
||||
}
|
||||
async listRegistrationApplications(
|
||||
...params: Parameters<BaseClient['listRegistrationApplications']>
|
||||
): ReturnType<BaseClient['listRegistrationApplications']> {
|
||||
return await this.#client.listRegistrationApplications(...params)
|
||||
}
|
||||
async approveRegistrationApplication(
|
||||
...params: Parameters<BaseClient['approveRegistrationApplication']>
|
||||
): ReturnType<BaseClient['approveRegistrationApplication']> {
|
||||
return await this.#client.approveRegistrationApplication(...params)
|
||||
}
|
||||
async getRegistrationApplication(
|
||||
...params: Parameters<BaseClient['getRegistrationApplication']>
|
||||
): ReturnType<BaseClient['getRegistrationApplication']> {
|
||||
return await this.#client.getRegistrationApplication(...params)
|
||||
}
|
||||
async purgePerson(
|
||||
...params: Parameters<BaseClient['purgePerson']>
|
||||
): ReturnType<BaseClient['purgePerson']> {
|
||||
return await this.#client.purgePerson(...params)
|
||||
}
|
||||
async purgeCommunity(
|
||||
...params: Parameters<BaseClient['purgeCommunity']>
|
||||
): ReturnType<BaseClient['purgeCommunity']> {
|
||||
return await this.#client.purgeCommunity(...params)
|
||||
}
|
||||
async purgePost(
|
||||
...params: Parameters<BaseClient['purgePost']>
|
||||
): ReturnType<BaseClient['purgePost']> {
|
||||
return await this.#client.purgePost(...params)
|
||||
}
|
||||
async purgeComment(
|
||||
...params: Parameters<BaseClient['purgeComment']>
|
||||
): ReturnType<BaseClient['purgeComment']> {
|
||||
return await this.#client.purgeComment(...params)
|
||||
}
|
||||
async getFederatedInstances(
|
||||
...params: Parameters<BaseClient['getFederatedInstances']>
|
||||
): ReturnType<BaseClient['getFederatedInstances']> {
|
||||
return await this.#client.getFederatedInstances(...params)
|
||||
}
|
||||
async blockInstance(
|
||||
...params: Parameters<BaseClient['blockInstance']>
|
||||
): ReturnType<BaseClient['blockInstance']> {
|
||||
return await this.#client.blockInstance(...params)
|
||||
}
|
||||
async uploadImage(
|
||||
...params: Parameters<BaseClient['uploadImage']>
|
||||
): ReturnType<BaseClient['uploadImage']> {
|
||||
return await this.#client.uploadImage(...params)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as lemmy from 'lemmy-js-client'
|
||||
import type { GetPosts, ListingType } from '../types'
|
||||
|
||||
export function fromGetPosts(getPosts: GetPosts): lemmy.GetPosts {
|
||||
return {
|
||||
...getPosts,
|
||||
type_: getPosts.type_ == 'Popular' ? 'All' : getPosts.type_,
|
||||
}
|
||||
}
|
||||
|
||||
export function toListingType(
|
||||
listingType?: ListingType,
|
||||
): lemmy.ListingType | undefined {
|
||||
if (listingType == 'Popular') listingType = 'All'
|
||||
return listingType
|
||||
}
|
||||
@@ -0,0 +1,911 @@
|
||||
import createClient from 'openapi-fetch'
|
||||
import type {
|
||||
BaseClient,
|
||||
ClientType,
|
||||
NullableFnArg,
|
||||
NullableFnReturn,
|
||||
} from '../base'
|
||||
import {
|
||||
fromCreateComment,
|
||||
fromCreatePost,
|
||||
fromGetComments,
|
||||
fromGetPost,
|
||||
fromGetPosts,
|
||||
fromGetReplies,
|
||||
fromListCommunities,
|
||||
fromSearch,
|
||||
toComment,
|
||||
toCommentReplyView,
|
||||
toCommentSortType,
|
||||
toCommentView,
|
||||
toCommunity,
|
||||
toCommunityView,
|
||||
toLocalSite,
|
||||
toMyUser,
|
||||
toPerson,
|
||||
toPersonMentionView,
|
||||
toPersonView,
|
||||
toPost,
|
||||
toPostView,
|
||||
toPrivateMessageView,
|
||||
toSortType,
|
||||
} from './rewrite'
|
||||
import type { paths } from './schema'
|
||||
|
||||
export class PiefedClient implements BaseClient {
|
||||
type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' }
|
||||
|
||||
#client: ReturnType<typeof createClient<paths>>
|
||||
|
||||
constructor(
|
||||
baseUrl: string,
|
||||
args: {
|
||||
fetchFunction: (input: any, init: any) => Promise<any>
|
||||
headers: any
|
||||
},
|
||||
) {
|
||||
this.#client = createClient({
|
||||
baseUrl: `${baseUrl}/api/alpha`,
|
||||
// @ts-expect-error i dont feel like fixing this right now
|
||||
fetch: args.fetchFunction,
|
||||
headers: args.headers,
|
||||
})
|
||||
}
|
||||
|
||||
async getSite(): ReturnType<BaseClient['getSite']> {
|
||||
const response = (await this.#client.GET('/site')).data!
|
||||
|
||||
return {
|
||||
admins: response.admins.map(toPersonView),
|
||||
site_view: {
|
||||
counts: {
|
||||
comments: -1,
|
||||
communities: -1,
|
||||
posts: -1,
|
||||
site_id: -1,
|
||||
users: response.site.user_count ?? -1,
|
||||
users_active_day: -1,
|
||||
users_active_half_year: -1,
|
||||
users_active_month: -1,
|
||||
users_active_week: -1,
|
||||
},
|
||||
local_site: toLocalSite(response.site),
|
||||
site: response.site,
|
||||
},
|
||||
all_languages:
|
||||
(response.site.all_languages as {
|
||||
code: string
|
||||
id: number
|
||||
name: string
|
||||
}[]) ?? [],
|
||||
blocked_urls: [],
|
||||
custom_emojis: [],
|
||||
discussion_languages: [],
|
||||
taglines: [],
|
||||
version: response.version,
|
||||
my_user: response.my_user ? toMyUser(response.my_user) : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
async createPost(
|
||||
params: Parameters<BaseClient['createPost']>[0],
|
||||
): ReturnType<BaseClient['createPost']> {
|
||||
const response = (
|
||||
await this.#client.POST('/post', {
|
||||
body: fromCreatePost(params),
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
async getPost(
|
||||
params: Parameters<BaseClient['getPost']>[0],
|
||||
): ReturnType<BaseClient['getPost']> {
|
||||
const response = (
|
||||
await this.#client.GET('/post', {
|
||||
// @ts-expect-error same here what is happening
|
||||
params: { query: fromGetPost(params) },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
community_view: toCommunityView(response.community_view),
|
||||
cross_posts: response.cross_posts.map(toPostView),
|
||||
moderators: response.moderators.map(i => ({
|
||||
community: toCommunity(i.community),
|
||||
moderator: toPerson(i.moderator),
|
||||
})),
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
|
||||
async editPost(
|
||||
params: Parameters<BaseClient['editPost']>[0],
|
||||
): ReturnType<BaseClient['editPost']> {
|
||||
const response = (await this.#client.PUT('/post', { body: params })).data!
|
||||
|
||||
return {
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
async deletePost(
|
||||
params: Parameters<BaseClient['deletePost']>[0],
|
||||
): ReturnType<BaseClient['deletePost']> {
|
||||
const response = (await this.#client.POST('/post/delete', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
|
||||
async removePost(
|
||||
params: Parameters<BaseClient['removePost']>[0],
|
||||
): ReturnType<BaseClient['removePost']> {
|
||||
const response = (await this.#client.POST('/post/remove', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
|
||||
async getPosts(
|
||||
params: Parameters<BaseClient['getPosts']>[0],
|
||||
): ReturnType<BaseClient['getPosts']> {
|
||||
const response = (
|
||||
await this.#client.GET('/post/list', {
|
||||
// @ts-expect-error same here what is happening
|
||||
params: { query: fromGetPosts(params) },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
posts: response.posts.map(toPostView),
|
||||
next_page: (Number(params.page_cursor ?? 1) + 1).toString(),
|
||||
}
|
||||
}
|
||||
async likePost(
|
||||
params: Parameters<BaseClient['likePost']>[0],
|
||||
): ReturnType<BaseClient['likePost']> {
|
||||
const response = (
|
||||
await this.#client.POST('/post/like', {
|
||||
body: { ...params },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
|
||||
async generateTotpSecret(): ReturnType<BaseClient['generateTotpSecret']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async listLogins(): ReturnType<BaseClient['listLogins']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async listAllMedia(): ReturnType<BaseClient['listAllMedia']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async updateTotp(): ReturnType<BaseClient['updateTotp']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getModlog(): ReturnType<BaseClient['getModlog']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async search(
|
||||
params: Parameters<BaseClient['search']>[0],
|
||||
): ReturnType<BaseClient['search']> {
|
||||
const response = (
|
||||
await this.#client.GET('/search', {
|
||||
params: {
|
||||
// @ts-expect-error same here what is happening
|
||||
query: fromSearch(params),
|
||||
},
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
comments: [],
|
||||
communities: response.communities.map(toCommunityView),
|
||||
posts: response.posts.map(toPostView),
|
||||
users: response.users.map(toPersonView),
|
||||
type_: response.type_,
|
||||
}
|
||||
}
|
||||
async resolveObject(
|
||||
params: Parameters<BaseClient['resolveObject']>[0],
|
||||
): ReturnType<BaseClient['resolveObject']> {
|
||||
const response = (
|
||||
await this.#client.GET('/resolve_object', {
|
||||
// @ts-expect-error same here what is happening
|
||||
params: { query: params },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
comment: response.comment ? toCommentView(response.comment) : undefined,
|
||||
community: response.community
|
||||
? toCommunityView(response.community)
|
||||
: undefined,
|
||||
post: response.post ? toPostView(response.post) : undefined,
|
||||
person: response.person ? toPersonView(response.person) : undefined,
|
||||
}
|
||||
}
|
||||
async createCommunity(
|
||||
params: Parameters<BaseClient['createCommunity']>[0],
|
||||
): ReturnType<BaseClient['createCommunity']> {
|
||||
const response = (await this.#client.POST('/community', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
community_view: toCommunityView(response.community_view),
|
||||
}
|
||||
}
|
||||
async getCommunity(
|
||||
params: Parameters<BaseClient['getCommunity']>[0],
|
||||
): ReturnType<BaseClient['getCommunity']> {
|
||||
const response = (
|
||||
await this.#client.GET('/community', {
|
||||
params: {
|
||||
// @ts-expect-error same here what is happening
|
||||
query: params,
|
||||
},
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
community_view: toCommunityView(response.community_view),
|
||||
moderators: response.moderators.map(i => ({
|
||||
community: toCommunity(i.community),
|
||||
moderator: toPerson(i.moderator),
|
||||
})),
|
||||
}
|
||||
}
|
||||
async editCommunity(
|
||||
params: Parameters<BaseClient['editCommunity']>[0],
|
||||
): ReturnType<BaseClient['editCommunity']> {
|
||||
const response = (
|
||||
await this.#client.PUT('/community', {
|
||||
body: { ...params, id: params.community_id },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
community_view: toCommunityView(response.community_view),
|
||||
}
|
||||
}
|
||||
async listCommunities(
|
||||
params: Parameters<BaseClient['listCommunities']>[0],
|
||||
): ReturnType<BaseClient['listCommunities']> {
|
||||
const response = (
|
||||
await this.#client.GET('/community/list', {
|
||||
params: {
|
||||
// @ts-expect-error same here what is happening
|
||||
query: fromListCommunities(params),
|
||||
},
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
communities: response.communities.map(toCommunityView),
|
||||
}
|
||||
}
|
||||
async followCommunity(
|
||||
params: Parameters<BaseClient['followCommunity']>[0],
|
||||
): ReturnType<BaseClient['followCommunity']> {
|
||||
const response = (
|
||||
await this.#client.POST('/community/follow', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
community_view: toCommunityView(response.community_view),
|
||||
}
|
||||
}
|
||||
async blockCommunity(
|
||||
params: Parameters<BaseClient['blockCommunity']>[0],
|
||||
): ReturnType<BaseClient['blockCommunity']> {
|
||||
const response = (
|
||||
await this.#client.POST('/community/block', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
community_view: toCommunityView(response.community_view),
|
||||
}
|
||||
}
|
||||
async deleteCommunity(
|
||||
params: Parameters<BaseClient['deleteCommunity']>[0],
|
||||
): ReturnType<BaseClient['deleteCommunity']> {
|
||||
const response = (
|
||||
await this.#client.POST('/community/delete', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
community_view: toCommunityView(response.community_view),
|
||||
}
|
||||
}
|
||||
async hideCommunity(): ReturnType<BaseClient['hideCommunity']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async removeCommunity(): ReturnType<BaseClient['removeCommunity']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async banFromCommunity(
|
||||
params: Parameters<BaseClient['banFromCommunity']>[0],
|
||||
): ReturnType<BaseClient['banFromCommunity']> {
|
||||
const response = // piefed has separate methods for ban/unban
|
||||
(
|
||||
params.ban
|
||||
? await this.#client.POST('/community/moderate/ban', {
|
||||
body: {
|
||||
...params,
|
||||
expiredAt: new Date(
|
||||
params.expires ?? '6767-06-07T00:00:00.000Z',
|
||||
).toISOString(),
|
||||
user_id: params.person_id,
|
||||
reason: params.reason ?? 'No reason provided.',
|
||||
},
|
||||
})
|
||||
: await this.#client.PUT('/community/moderate/unban', {
|
||||
body: {
|
||||
community_id: params.community_id,
|
||||
user_id: params.person_id,
|
||||
},
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
banned: params.ban,
|
||||
person_view: {
|
||||
person: toPerson(response.bannedUser),
|
||||
counts: { comment_count: -1, person_id: -1, post_count: -1 },
|
||||
is_admin: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
async addModToCommunity(
|
||||
params: Parameters<BaseClient['addModToCommunity']>[0],
|
||||
): ReturnType<BaseClient['addModToCommunity']> {
|
||||
const response = (
|
||||
await this.#client.POST('/community/mod', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
moderators: response.moderators.map(i => ({
|
||||
community: toCommunity(i.community),
|
||||
moderator: toPerson(i.moderator),
|
||||
})),
|
||||
}
|
||||
}
|
||||
async markPostAsRead(
|
||||
params: Parameters<BaseClient['markPostAsRead']>[0],
|
||||
): ReturnType<BaseClient['markPostAsRead']> {
|
||||
await this.#client.POST('/post/mark_as_read', {
|
||||
body: { ...params },
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
}
|
||||
}
|
||||
async hidePost(): ReturnType<BaseClient['hidePost']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async lockPost(
|
||||
params: Parameters<BaseClient['lockPost']>[0],
|
||||
): ReturnType<BaseClient['lockPost']> {
|
||||
const response = (await this.#client.POST('/post/lock', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
async featurePost(
|
||||
params: Parameters<BaseClient['featurePost']>[0],
|
||||
): ReturnType<BaseClient['featurePost']> {
|
||||
const response = (
|
||||
await this.#client.POST('/post/feature', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
async listPostLikes(): ReturnType<BaseClient['listPostLikes']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async savePost(
|
||||
params: Parameters<BaseClient['savePost']>[0],
|
||||
): ReturnType<BaseClient['savePost']> {
|
||||
const response = (await this.#client.PUT('/post/save', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
post_view: toPostView(response.post_view),
|
||||
}
|
||||
}
|
||||
async createPostReport(
|
||||
params: Parameters<BaseClient['createPostReport']>[0],
|
||||
): ReturnType<BaseClient['createPostReport']> {
|
||||
const response = (await this.#client.POST('/post/report', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
post_report_view: {
|
||||
...response.post_report_view,
|
||||
community: toCommunity(response.post_report_view.community),
|
||||
post: toPost(response.post_report_view.post),
|
||||
creator: toPerson(response.post_report_view.creator),
|
||||
resolver: response.post_report_view.resolver
|
||||
? toPerson(response.post_report_view.resolver)
|
||||
: undefined,
|
||||
post_creator: toPerson(response.post_report_view.post_creator),
|
||||
read: false,
|
||||
hidden: false,
|
||||
creator_banned_from_community: false,
|
||||
unread_comments: -1,
|
||||
},
|
||||
}
|
||||
}
|
||||
async resolvePostReport(): ReturnType<BaseClient['resolvePostReport']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async listPostReports(): ReturnType<BaseClient['listPostReports']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getSiteMetadata(): ReturnType<BaseClient['getSiteMetadata']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
|
||||
async createComment(
|
||||
params: Parameters<BaseClient['createComment']>[0],
|
||||
): ReturnType<BaseClient['createComment']> {
|
||||
const response = (
|
||||
await this.#client.POST('/comment', {
|
||||
body: fromCreateComment(params),
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
async editComment(
|
||||
params: Parameters<BaseClient['editComment']>[0],
|
||||
): ReturnType<BaseClient['editComment']> {
|
||||
const response = (await this.#client.PUT('/comment', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
async deleteComment(
|
||||
params: Parameters<BaseClient['deleteComment']>[0],
|
||||
): ReturnType<BaseClient['deleteComment']> {
|
||||
const response = (
|
||||
await this.#client.POST('/comment/delete', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
async removeComment(
|
||||
params: Parameters<BaseClient['removeComment']>[0],
|
||||
): ReturnType<BaseClient['removeComment']> {
|
||||
const response = (
|
||||
await this.#client.POST('/comment/remove', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
async markCommentReplyAsRead(
|
||||
params: Parameters<BaseClient['markCommentReplyAsRead']>[0],
|
||||
): ReturnType<BaseClient['markCommentReplyAsRead']> {
|
||||
await this.#client.POST('/comment/mark_as_read', {
|
||||
body: params,
|
||||
})
|
||||
}
|
||||
async likeComment(
|
||||
params: Parameters<BaseClient['likeComment']>[0],
|
||||
): ReturnType<BaseClient['likeComment']> {
|
||||
// TODO remove any
|
||||
const response = (
|
||||
await this.#client.POST('/comment/like', {
|
||||
body: params,
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
|
||||
async listCommentLikes(): ReturnType<BaseClient['listCommentLikes']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async saveComment(
|
||||
params: Parameters<BaseClient['saveComment']>[0],
|
||||
): ReturnType<BaseClient['saveComment']> {
|
||||
const response = (await this.#client.PUT('/comment/save', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
async distinguishComment(): ReturnType<BaseClient['distinguishComment']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
|
||||
async getComments(
|
||||
params: Parameters<BaseClient['getComments']>[0],
|
||||
): ReturnType<BaseClient['getComments']> {
|
||||
const response = (
|
||||
await this.#client.GET('/comment/list', {
|
||||
// @ts-expect-error same here what is happening
|
||||
params: { query: fromGetComments(params) },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
comments: response.comments.map(toCommentView),
|
||||
}
|
||||
}
|
||||
|
||||
async getComment(
|
||||
params: Parameters<BaseClient['getComment']>[0],
|
||||
): ReturnType<BaseClient['getComment']> {
|
||||
const response =
|
||||
// @ts-expect-error same here what is happening
|
||||
(await this.#client.GET('/comment', { params: { query: params } })).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
comment_view: toCommentView(response.comment_view),
|
||||
recipient_ids: [],
|
||||
}
|
||||
}
|
||||
async createCommentReport(
|
||||
params: Parameters<BaseClient['createCommentReport']>[0],
|
||||
): ReturnType<BaseClient['createCommentReport']> {
|
||||
const response = (
|
||||
await this.#client.POST('/comment/report', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
comment_report_view: {
|
||||
...response.comment_report_view,
|
||||
comment: toComment(response.comment_report_view.comment),
|
||||
community: toCommunity(response.comment_report_view.community),
|
||||
comment_creator: toPerson(response.comment_report_view.comment_creator),
|
||||
creator: toPerson(response.comment_report_view.creator),
|
||||
post: toPost(response.comment_report_view.post),
|
||||
resolver: response.comment_report_view.resolver
|
||||
? toPerson(response.comment_report_view.resolver)
|
||||
: undefined,
|
||||
},
|
||||
}
|
||||
}
|
||||
async resolveCommentReport(): ReturnType<BaseClient['resolveCommentReport']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async listCommentReports(): ReturnType<BaseClient['listCommentReports']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getPrivateMessages(
|
||||
params: Parameters<BaseClient['getPrivateMessages']>[0],
|
||||
): ReturnType<BaseClient['getPrivateMessages']> {
|
||||
const response = (
|
||||
await this.#client.GET('/private_message/list', {
|
||||
// @ts-expect-error query params are screwed up
|
||||
params: { query: params },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
private_messages: response.private_messages.map(toPrivateMessageView),
|
||||
}
|
||||
}
|
||||
async createPrivateMessage(
|
||||
params: Parameters<BaseClient['createPrivateMessage']>[0],
|
||||
): ReturnType<BaseClient['createPrivateMessage']> {
|
||||
const response = (
|
||||
await this.#client.POST('/private_message', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
private_message_view: toPrivateMessageView(response.private_message_view),
|
||||
}
|
||||
}
|
||||
async editPrivateMessage(
|
||||
params: Parameters<BaseClient['editPrivateMessage']>[0],
|
||||
): ReturnType<BaseClient['editPrivateMessage']> {
|
||||
const response = (
|
||||
await this.#client.PUT('/private_message', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
private_message_view: toPrivateMessageView(response.private_message_view),
|
||||
}
|
||||
}
|
||||
async deletePrivateMessage(
|
||||
params: Parameters<BaseClient['deletePrivateMessage']>[0],
|
||||
): ReturnType<BaseClient['deletePrivateMessage']> {
|
||||
const response = (
|
||||
await this.#client.POST('/private_message/delete', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
private_message_view: toPrivateMessageView(response.private_message_view),
|
||||
}
|
||||
}
|
||||
async markPrivateMessageAsRead(
|
||||
params: Parameters<BaseClient['markPrivateMessageAsRead']>[0],
|
||||
): ReturnType<BaseClient['markPrivateMessageAsRead']> {
|
||||
const response = (
|
||||
await this.#client.POST('/private_message/mark_as_read', { body: params })
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
private_message_view: toPrivateMessageView(response.private_message_view),
|
||||
}
|
||||
}
|
||||
async createPrivateMessageReport(): ReturnType<
|
||||
BaseClient['createPrivateMessageReport']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async resolvePrivateMessageReport(): ReturnType<
|
||||
BaseClient['resolvePrivateMessageReport']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async listPrivateMessageReports(): ReturnType<
|
||||
BaseClient['listPrivateMessageReports']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async register(): ReturnType<BaseClient['register']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async login(
|
||||
params: Parameters<BaseClient['login']>[0],
|
||||
): ReturnType<BaseClient['login']> {
|
||||
const response = await this.#client.POST('/user/login', {
|
||||
body: { username: params.username_or_email, password: params.password },
|
||||
})!
|
||||
|
||||
return {
|
||||
verify_email_sent: false,
|
||||
registration_created: false,
|
||||
jwt: response.data?.jwt,
|
||||
}
|
||||
}
|
||||
async logout(): ReturnType<BaseClient['logout']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getPersonDetails(
|
||||
params: Parameters<BaseClient['getPersonDetails']>[0],
|
||||
): ReturnType<BaseClient['getPersonDetails']> {
|
||||
const response = (
|
||||
await this.#client.GET('/user', {
|
||||
params: {
|
||||
query: {
|
||||
...params,
|
||||
// @ts-expect-error more param cursedness
|
||||
include_content: true,
|
||||
sort: toSortType(params.sort),
|
||||
},
|
||||
},
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
comments: response.comments.map(toCommentView),
|
||||
moderates: response.moderates.map(i => ({
|
||||
community: toCommunity(i.community),
|
||||
moderator: toPerson(i.moderator),
|
||||
})),
|
||||
person_view: toPersonView(response.person_view),
|
||||
posts: response.posts.map(toPostView),
|
||||
}
|
||||
}
|
||||
async getPersonMentions(
|
||||
params: Parameters<BaseClient['getPersonMentions']>[0],
|
||||
): ReturnType<BaseClient['getPersonMentions']> {
|
||||
const response = (
|
||||
await this.#client.GET('/user/mentions', {
|
||||
// @ts-expect-error yet another query param bug
|
||||
params: { query: { ...params, sort: toCommentSortType(params.sort) } },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
mentions: response.replies.map(toPersonMentionView),
|
||||
}
|
||||
}
|
||||
async markPersonMentionAsRead(
|
||||
params: Parameters<BaseClient['markPersonMentionAsRead']>[0],
|
||||
): ReturnType<BaseClient['markPersonMentionAsRead']> {
|
||||
// @ts-expect-error this method isnt documented
|
||||
await this.#client.POST('/mention/mark_as_read', {
|
||||
body: params,
|
||||
})
|
||||
}
|
||||
async getReplies(
|
||||
params: Parameters<BaseClient['getReplies']>[0],
|
||||
): ReturnType<BaseClient['getReplies']> {
|
||||
const response = (
|
||||
await this.#client.GET('/user/replies', {
|
||||
// @ts-expect-error same here what is happening
|
||||
params: { query: fromGetReplies(params) },
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
replies: response.replies.map(toCommentReplyView),
|
||||
}
|
||||
}
|
||||
async banPerson(): ReturnType<BaseClient['banPerson']> {
|
||||
// this is for site view not community view
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getBannedPersons(): ReturnType<BaseClient['getBannedPersons']> {
|
||||
// this is for site view not community view
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async blockPerson(
|
||||
params: Parameters<BaseClient['blockPerson']>[0],
|
||||
): ReturnType<BaseClient['blockPerson']> {
|
||||
const response = (await this.#client.POST('/user/block', { body: params }))
|
||||
.data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
person_view: toPersonView(response.person_view),
|
||||
}
|
||||
}
|
||||
async getCaptcha(): ReturnType<BaseClient['getCaptcha']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async deleteAccount(): ReturnType<BaseClient['deleteAccount']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async passwordReset(): ReturnType<BaseClient['passwordReset']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async passwordChangeAfterReset(): ReturnType<
|
||||
BaseClient['passwordChangeAfterReset']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async markAllAsRead(): ReturnType<BaseClient['markAllAsRead']> {
|
||||
const response = (await this.#client.POST('/user/mark_all_as_read')).data!
|
||||
|
||||
return {
|
||||
replies: response.replies.map(toCommentReplyView),
|
||||
}
|
||||
}
|
||||
async saveUserSettings(
|
||||
params: Parameters<BaseClient['saveUserSettings']>[0],
|
||||
): ReturnType<BaseClient['saveUserSettings']> {
|
||||
return (
|
||||
await this.#client.PUT('/user/save_user_settings', { body: params })
|
||||
).data!
|
||||
}
|
||||
async changePassword(): ReturnType<BaseClient['changePassword']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getReportCount(): ReturnType<BaseClient['getReportCount']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getUnreadCount(): ReturnType<BaseClient['getUnreadCount']> {
|
||||
return (await this.#client.GET('/user/unread_count')).data!
|
||||
}
|
||||
async verifyEmail(): ReturnType<BaseClient['verifyEmail']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async addAdmin(): ReturnType<BaseClient['addAdmin']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getUnreadRegistrationApplicationCount(): ReturnType<
|
||||
BaseClient['getUnreadRegistrationApplicationCount']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async listRegistrationApplications(): ReturnType<
|
||||
BaseClient['listRegistrationApplications']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async approveRegistrationApplication(): ReturnType<
|
||||
BaseClient['approveRegistrationApplication']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getRegistrationApplication(): ReturnType<
|
||||
BaseClient['getRegistrationApplication']
|
||||
> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async purgePerson(): ReturnType<BaseClient['purgePerson']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async purgeCommunity(): ReturnType<BaseClient['purgeCommunity']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async purgePost(): ReturnType<BaseClient['purgePost']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async purgeComment(): ReturnType<BaseClient['purgeComment']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async getFederatedInstances(): ReturnType<
|
||||
BaseClient['getFederatedInstances']
|
||||
> {
|
||||
return (await this.#client.GET('/federated_instances')).data!
|
||||
}
|
||||
async blockInstance(
|
||||
params: Parameters<BaseClient['blockInstance']>[0],
|
||||
): ReturnType<BaseClient['blockInstance']> {
|
||||
return (await this.#client.POST('/site/block', { body: { ...params } }))!
|
||||
.data!
|
||||
}
|
||||
async uploadImage(
|
||||
params: Parameters<BaseClient['uploadImage']>[0],
|
||||
): ReturnType<BaseClient['uploadImage']> {
|
||||
const formData = new FormData()
|
||||
formData.append('file', params.image as File)
|
||||
|
||||
const response = (
|
||||
await this.#client.POST('/upload/image', {
|
||||
// @ts-expect-error this is the only working way to do this
|
||||
body: formData,
|
||||
})
|
||||
).data!
|
||||
|
||||
return {
|
||||
...response,
|
||||
msg: 'yeah it worked i think',
|
||||
}
|
||||
}
|
||||
|
||||
async setFlair(
|
||||
params: NullableFnArg<BaseClient['setFlair']>[0],
|
||||
): NullableFnReturn<BaseClient['setFlair']> {
|
||||
const response = (
|
||||
await this.#client.POST('/user/set_flair', { body: params })
|
||||
).data!
|
||||
|
||||
return toPersonView(response.person_view)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
import type {
|
||||
Comment,
|
||||
CommentReplyView,
|
||||
CommentSortType,
|
||||
CommentView,
|
||||
Community,
|
||||
CommunityView,
|
||||
CreateComment,
|
||||
CreatePost,
|
||||
GetComments,
|
||||
GetPost,
|
||||
GetPosts,
|
||||
GetReplies,
|
||||
ListCommunities,
|
||||
LocalSite,
|
||||
MyUserInfo,
|
||||
Person,
|
||||
PersonMentionView,
|
||||
PersonView,
|
||||
Post,
|
||||
PostView,
|
||||
PrivateMessageView,
|
||||
Search,
|
||||
SortType,
|
||||
} from '../types'
|
||||
import type { components } from './schema'
|
||||
|
||||
export function toPersonView(
|
||||
personView: components['schemas']['PersonView'],
|
||||
): PersonView {
|
||||
return {
|
||||
counts: personView.counts,
|
||||
is_admin: personView.is_admin,
|
||||
person: toPerson(personView.person),
|
||||
}
|
||||
}
|
||||
|
||||
export function toPerson(person: components['schemas']['Person']): Person {
|
||||
return {
|
||||
...person,
|
||||
id: person.id,
|
||||
name: person.user_name,
|
||||
bot_account: person.bot,
|
||||
}
|
||||
}
|
||||
|
||||
export function toLocalSite(site: components['schemas']['Site']): LocalSite {
|
||||
if (site) return {}
|
||||
return {}
|
||||
}
|
||||
|
||||
export function toCommunityView(
|
||||
communityView: components['schemas']['CommunityView'],
|
||||
): CommunityView {
|
||||
return {
|
||||
...communityView,
|
||||
community: toCommunity(communityView.community),
|
||||
banned_from_community: false,
|
||||
counts: {
|
||||
comments: communityView.counts.post_reply_count,
|
||||
posts: communityView.counts.post_count,
|
||||
subscribers: communityView.counts.total_subscriptions_count,
|
||||
published: communityView.community.published,
|
||||
community_id: communityView.community.id,
|
||||
subscribers_local: communityView.counts.subscriptions_count,
|
||||
users_active_day: communityView.counts.active_daily,
|
||||
users_active_half_year: communityView.counts.active_6monthly,
|
||||
users_active_month: communityView.counts.active_monthly,
|
||||
users_active_week: communityView.counts.active_weekly,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function toCommunity(
|
||||
community: components['schemas']['Community'],
|
||||
): Community {
|
||||
return {
|
||||
...community,
|
||||
posting_restricted_to_mods: false,
|
||||
visibility: 'Public',
|
||||
}
|
||||
}
|
||||
|
||||
export function toMyUser(
|
||||
myUser: components['schemas']['MyUserInfo'],
|
||||
): MyUserInfo {
|
||||
return {
|
||||
...myUser,
|
||||
community_blocks: myUser.community_blocks.map(i => ({
|
||||
community: toCommunity(i.community),
|
||||
person: toPerson(i.person),
|
||||
})),
|
||||
local_user_view: {
|
||||
...myUser.local_user_view,
|
||||
local_user: {
|
||||
...myUser.local_user_view.local_user,
|
||||
id: myUser.local_user_view.person.id,
|
||||
person_id: myUser.local_user_view.person.id,
|
||||
totp_2fa_enabled: false,
|
||||
default_listing_type: 'All',
|
||||
},
|
||||
person: toPerson(myUser.local_user_view.person),
|
||||
},
|
||||
follows: myUser.follows.map(i => ({
|
||||
follower: toPerson(i.follower),
|
||||
community: toCommunity(i.community),
|
||||
})),
|
||||
moderates: myUser.moderates.map(i => ({
|
||||
community: toCommunity(i.community),
|
||||
moderator: toPerson(i.moderator),
|
||||
})),
|
||||
instance_blocks: myUser.instance_blocks.map(i => ({
|
||||
instance: i.instance,
|
||||
person: toPerson(i.person),
|
||||
})),
|
||||
person_blocks: myUser.person_blocks.map(i => ({
|
||||
person: toPerson(i.person),
|
||||
target: toPerson(i.target),
|
||||
})),
|
||||
discussion_languages: myUser.discussion_languages.map(i => i.id!),
|
||||
}
|
||||
}
|
||||
|
||||
export function toPostView(
|
||||
postView: components['schemas']['PostView'],
|
||||
): PostView {
|
||||
return {
|
||||
...postView,
|
||||
creator: toPerson(postView.creator),
|
||||
creator_blocked: false,
|
||||
post: toPost(postView.post),
|
||||
community: toCommunity(postView.community),
|
||||
}
|
||||
}
|
||||
|
||||
export function toPost(post: components['schemas']['Post']): Post {
|
||||
return {
|
||||
...post,
|
||||
creator_id: -1,
|
||||
name: post.title,
|
||||
featured_community: post.sticky,
|
||||
featured_local: false,
|
||||
}
|
||||
}
|
||||
|
||||
export function toCommentView(
|
||||
commentView: components['schemas']['CommentView'],
|
||||
): CommentView {
|
||||
return {
|
||||
...commentView,
|
||||
comment: toComment(commentView.comment),
|
||||
creator: toPerson(commentView.creator),
|
||||
post: toPost(commentView.post),
|
||||
community: toCommunity(commentView.community),
|
||||
}
|
||||
}
|
||||
|
||||
export function toComment(comment: components['schemas']['Comment']): Comment {
|
||||
return {
|
||||
...comment,
|
||||
content: comment.body,
|
||||
creator_id: -1,
|
||||
distinguished: comment.distinguished ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
export function toCommentReplyView(
|
||||
commentReplyView: components['schemas']['CommentReplyView'],
|
||||
): CommentReplyView {
|
||||
return {
|
||||
...commentReplyView,
|
||||
banned_from_community: false,
|
||||
creator_banned_from_community: false,
|
||||
comment: toComment(commentReplyView.comment),
|
||||
creator: toPerson(commentReplyView.creator),
|
||||
post: toPost(commentReplyView.post),
|
||||
community: toCommunity(commentReplyView.community),
|
||||
recipient: toPerson(commentReplyView.recipient),
|
||||
}
|
||||
}
|
||||
|
||||
export function toPrivateMessageView(
|
||||
privateMessageView: components['schemas']['PrivateMessageView'],
|
||||
): PrivateMessageView {
|
||||
return {
|
||||
...privateMessageView,
|
||||
creator: toPerson(privateMessageView.creator),
|
||||
recipient: toPerson(privateMessageView.recipient),
|
||||
}
|
||||
}
|
||||
|
||||
export function toPersonMentionView(
|
||||
personMentionView: components['schemas']['CommentReplyView'],
|
||||
): PersonMentionView {
|
||||
return {
|
||||
...personMentionView,
|
||||
person_mention: personMentionView.comment_reply,
|
||||
creator_banned_from_community: false,
|
||||
banned_from_community: false,
|
||||
comment: toComment(personMentionView.comment),
|
||||
community: toCommunity(personMentionView.community),
|
||||
post: toPost(personMentionView.post),
|
||||
creator: toPerson(personMentionView.creator),
|
||||
recipient: toPerson(personMentionView.recipient),
|
||||
}
|
||||
}
|
||||
|
||||
// Query calls
|
||||
export function fromGetPosts(
|
||||
getPosts: GetPosts,
|
||||
): components['schemas']['GetPosts'] {
|
||||
return {
|
||||
...getPosts,
|
||||
sort: toSortType(getPosts.sort),
|
||||
page_cursor: Number(getPosts.page_cursor),
|
||||
}
|
||||
}
|
||||
|
||||
export function fromGetComments(
|
||||
getComments: GetComments,
|
||||
): components['schemas']['GetComments'] {
|
||||
return {
|
||||
...getComments,
|
||||
sort: toCommentSortType(getComments.sort),
|
||||
}
|
||||
}
|
||||
|
||||
export function fromGetPost(
|
||||
getPost: GetPost,
|
||||
): components['schemas']['GetPost'] {
|
||||
return getPost
|
||||
}
|
||||
|
||||
export function fromGetReplies(
|
||||
getReplies: GetReplies,
|
||||
): components['schemas']['GetReplies'] {
|
||||
return {
|
||||
...getReplies,
|
||||
sort: toCommentSortType(getReplies.sort),
|
||||
}
|
||||
}
|
||||
|
||||
export function fromSearch(search: Search): components['schemas']['Search'] {
|
||||
return {
|
||||
...(search as Omit<Search, 'type_'> & {
|
||||
type_: 'Communities' | 'Users' | 'Url' | 'Posts'
|
||||
}),
|
||||
sort: toSortType(search.sort),
|
||||
}
|
||||
}
|
||||
|
||||
export function fromCreatePost(
|
||||
createPost: CreatePost,
|
||||
): components['schemas']['CreatePost'] {
|
||||
return {
|
||||
...createPost,
|
||||
title: createPost.name,
|
||||
}
|
||||
}
|
||||
|
||||
export function fromListCommunities(
|
||||
listCommunities: ListCommunities,
|
||||
): components['schemas']['ListCommunities'] {
|
||||
return {
|
||||
...listCommunities,
|
||||
// @ts-expect-error ok so the api tells me something different than the actual dev api tells me to do
|
||||
sort: toCommunitiesSortType(listCommunities.sort),
|
||||
}
|
||||
}
|
||||
|
||||
export function fromCreateComment(
|
||||
createComment: CreateComment,
|
||||
): components['schemas']['CreateComment'] {
|
||||
return {
|
||||
...createComment,
|
||||
body: createComment.content,
|
||||
}
|
||||
}
|
||||
|
||||
// Misc
|
||||
export function toSortType(
|
||||
sortType?: SortType,
|
||||
): components['schemas']['SortType'] | undefined {
|
||||
if (
|
||||
sortType == 'Old' ||
|
||||
sortType == 'MostComments' ||
|
||||
sortType == 'Controversial' ||
|
||||
sortType == 'NewComments'
|
||||
)
|
||||
sortType = 'New'
|
||||
return sortType
|
||||
}
|
||||
|
||||
export function toCommentSortType(
|
||||
commentSortType?: CommentSortType,
|
||||
): components['schemas']['CommentSortType'] | undefined {
|
||||
if (commentSortType == 'Controversial') commentSortType = undefined
|
||||
return commentSortType
|
||||
}
|
||||
|
||||
export function toCommunitiesSortType(
|
||||
sortType?: SortType,
|
||||
): 'Top' | 'Hot' | 'New' | undefined {
|
||||
if (sortType == 'Hot' || sortType == 'New' || sortType == undefined)
|
||||
return sortType
|
||||
else return 'Top'
|
||||
}
|
||||
Vendored
+5460
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,65 @@
|
||||
export * from './schemas/AddAdminResponse'
|
||||
export * from './schemas/AddModToCommunityResponse'
|
||||
export * from './schemas/BanFromCommunityResponse'
|
||||
export * from './schemas/BanPersonResponse'
|
||||
export * from './schemas/BannedPersonsResponse'
|
||||
export * from './schemas/BlockCommunityResponse'
|
||||
export * from './schemas/BlockInstanceResponse'
|
||||
export * from './schemas/BlockPersonResponse'
|
||||
export * from './schemas/CaptchaResponse'
|
||||
export * from './schemas/CommentReplyResponse'
|
||||
export * from './schemas/CommentReportResponse'
|
||||
export * from './schemas/CommentResponse'
|
||||
export * from './schemas/CommunityResponse'
|
||||
export * from './schemas/CustomEmojiResponse'
|
||||
export * from './schemas/GenerateTotpSecretResponse'
|
||||
export * from './schemas/GetCaptchaResponse'
|
||||
export * from './schemas/GetComment'
|
||||
export * from './schemas/GetComments'
|
||||
export * from './schemas/GetCommentsResponse'
|
||||
export * from './schemas/GetCommunity'
|
||||
export * from './schemas/GetCommunityResponse'
|
||||
export * from './schemas/GetFederatedInstancesResponse'
|
||||
export * from './schemas/GetModlog'
|
||||
export * from './schemas/GetModlogResponse'
|
||||
export * from './schemas/GetPersonDetails'
|
||||
export * from './schemas/GetPersonDetailsResponse'
|
||||
export * from './schemas/GetPersonMentions'
|
||||
export * from './schemas/GetPersonMentionsResponse'
|
||||
export * from './schemas/GetPost'
|
||||
export * from './schemas/GetPostResponse'
|
||||
export * from './schemas/GetPosts'
|
||||
export * from './schemas/GetPostsResponse'
|
||||
export * from './schemas/GetPrivateMessages'
|
||||
export * from './schemas/GetRegistrationApplication'
|
||||
export * from './schemas/GetReplies'
|
||||
export * from './schemas/GetRepliesResponse'
|
||||
export * from './schemas/GetReportCount'
|
||||
export * from './schemas/GetReportCountResponse'
|
||||
export * from './schemas/GetSiteMetadata'
|
||||
export * from './schemas/GetSiteMetadataResponse'
|
||||
export * from './schemas/GetSiteResponse'
|
||||
export * from './schemas/GetUnreadCountResponse'
|
||||
export * from './schemas/GetUnreadRegistrationApplicationCountResponse'
|
||||
export * from './schemas/ListCommentLikesResponse'
|
||||
export * from './schemas/ListCommentReportsResponse'
|
||||
export * from './schemas/ListCommunitiesResponse'
|
||||
export * from './schemas/ListMediaResponse'
|
||||
export * from './schemas/ListPostLikesResponse'
|
||||
export * from './schemas/ListPostReportsResponse'
|
||||
export * from './schemas/ListPrivateMessageReportsResponse'
|
||||
export * from './schemas/ListRegistrationApplicationsResponse'
|
||||
export * from './schemas/LoginResponse'
|
||||
export * from './schemas/PersonMentionResponse'
|
||||
export * from './schemas/PostReportResponse'
|
||||
export * from './schemas/PostResponse'
|
||||
export * from './schemas/PrivateMessageReportResponse'
|
||||
export * from './schemas/PrivateMessageResponse'
|
||||
export * from './schemas/PrivateMessagesResponse'
|
||||
export * from './schemas/RegistrationApplicationResponse'
|
||||
export * from './schemas/ResolveObjectResponse'
|
||||
export * from './schemas/SearchResponse'
|
||||
export * from './schemas/SiteResponse'
|
||||
export * from './schemas/SuccessResponse'
|
||||
export * from './schemas/UpdateTotpResponse'
|
||||
export * from './schemas/schemas'
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PersonView } from './schemas'
|
||||
export interface AddAdminResponse {
|
||||
admins: Array<PersonView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommunityModeratorView } from './schemas'
|
||||
export interface AddModToCommunityResponse {
|
||||
moderators: Array<CommunityModeratorView>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { PersonView } from './schemas'
|
||||
export interface BanFromCommunityResponse {
|
||||
person_view: PersonView
|
||||
banned: boolean
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { PersonView } from './schemas'
|
||||
export interface BanPersonResponse {
|
||||
person_view: PersonView
|
||||
banned: boolean
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PersonView } from './schemas'
|
||||
export interface BannedPersonsResponse {
|
||||
banned: Array<PersonView>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { CommunityView } from './schemas'
|
||||
export interface BlockCommunityResponse {
|
||||
community_view: CommunityView
|
||||
blocked: boolean
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface BlockInstanceResponse {
|
||||
blocked: boolean;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { PersonView } from './schemas'
|
||||
export interface BlockPersonResponse {
|
||||
person_view: PersonView
|
||||
blocked: boolean
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface CaptchaResponse {
|
||||
png: string;
|
||||
wav: string;
|
||||
uuid: string;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommentReplyView } from './schemas'
|
||||
export interface CommentReplyResponse {
|
||||
comment_reply_view: CommentReplyView
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommentReportView } from './schemas'
|
||||
export interface CommentReportResponse {
|
||||
comment_report_view: CommentReportView
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { CommentView } from './schemas'
|
||||
import type { LocalUserId } from './schemas'
|
||||
export interface CommentResponse {
|
||||
comment_view: CommentView
|
||||
recipient_ids: Array<LocalUserId>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { CommunityView } from './schemas'
|
||||
import type { LanguageId } from './schemas'
|
||||
export interface CommunityResponse {
|
||||
community_view: CommunityView
|
||||
discussion_languages: Array<LanguageId>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CustomEmojiView } from './schemas'
|
||||
export interface CustomEmojiResponse {
|
||||
custom_emoji: CustomEmojiView
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface GenerateTotpSecretResponse {
|
||||
totp_secret_url: string;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CaptchaResponse } from './schemas'
|
||||
export interface GetCaptchaResponse {
|
||||
ok?: CaptchaResponse
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommentId } from './schemas'
|
||||
export interface GetComment {
|
||||
id: CommentId
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { CommentId } from './schemas'
|
||||
import type { CommentSortType } from './schemas'
|
||||
import type { CommunityId } from './schemas'
|
||||
import type { ListingType } from './schemas'
|
||||
import type { PostId } from './schemas'
|
||||
export interface GetComments {
|
||||
type_?: ListingType
|
||||
sort?: CommentSortType
|
||||
max_depth?: number
|
||||
page?: number
|
||||
limit?: number
|
||||
community_id?: CommunityId
|
||||
community_name?: string
|
||||
post_id?: PostId
|
||||
parent_id?: CommentId
|
||||
saved_only?: boolean
|
||||
liked_only?: boolean
|
||||
disliked_only?: boolean
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommentView } from './schemas'
|
||||
export interface GetCommentsResponse {
|
||||
comments: Array<CommentView>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { CommunityId } from './schemas'
|
||||
export interface GetCommunity {
|
||||
id?: CommunityId
|
||||
name?: string
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { CommunityModeratorView } from './schemas'
|
||||
import type { CommunityView } from './schemas'
|
||||
import type { LanguageId } from './schemas'
|
||||
import type { Site } from './schemas'
|
||||
export interface GetCommunityResponse {
|
||||
community_view: CommunityView
|
||||
site?: Site
|
||||
moderators: Array<CommunityModeratorView>
|
||||
discussion_languages: Array<LanguageId>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { FederatedInstances } from './schemas'
|
||||
export interface GetFederatedInstancesResponse {
|
||||
federated_instances?: FederatedInstances
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { CommentId } from './schemas'
|
||||
import type { CommunityId } from './schemas'
|
||||
import type { ModlogActionType } from './schemas'
|
||||
import type { PersonId } from './schemas'
|
||||
import type { PostId } from './schemas'
|
||||
export interface GetModlog {
|
||||
mod_person_id?: PersonId
|
||||
community_id?: CommunityId
|
||||
page?: number
|
||||
limit?: number
|
||||
type_?: ModlogActionType
|
||||
other_person_id?: PersonId
|
||||
post_id?: PostId
|
||||
comment_id?: CommentId
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { AdminPurgeCommentView } from './schemas'
|
||||
import type { AdminPurgeCommunityView } from './schemas'
|
||||
import type { AdminPurgePersonView } from './schemas'
|
||||
import type { AdminPurgePostView } from './schemas'
|
||||
import type { ModAddCommunityView } from './schemas'
|
||||
import type { ModAddView } from './schemas'
|
||||
import type { ModBanFromCommunityView } from './schemas'
|
||||
import type { ModBanView } from './schemas'
|
||||
import type { ModFeaturePostView } from './schemas'
|
||||
import type { ModHideCommunityView } from './schemas'
|
||||
import type { ModLockPostView } from './schemas'
|
||||
import type { ModRemoveCommentView } from './schemas'
|
||||
import type { ModRemoveCommunityView } from './schemas'
|
||||
import type { ModRemovePostView } from './schemas'
|
||||
import type { ModTransferCommunityView } from './schemas'
|
||||
export interface GetModlogResponse {
|
||||
removed_posts: Array<ModRemovePostView>
|
||||
locked_posts: Array<ModLockPostView>
|
||||
featured_posts: Array<ModFeaturePostView>
|
||||
removed_comments: Array<ModRemoveCommentView>
|
||||
removed_communities: Array<ModRemoveCommunityView>
|
||||
banned_from_community: Array<ModBanFromCommunityView>
|
||||
banned: Array<ModBanView>
|
||||
added_to_community: Array<ModAddCommunityView>
|
||||
transferred_to_community: Array<ModTransferCommunityView>
|
||||
added: Array<ModAddView>
|
||||
admin_purged_persons: Array<AdminPurgePersonView>
|
||||
admin_purged_communities: Array<AdminPurgeCommunityView>
|
||||
admin_purged_posts: Array<AdminPurgePostView>
|
||||
admin_purged_comments: Array<AdminPurgeCommentView>
|
||||
hidden_communities: Array<ModHideCommunityView>
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { CommunityId } from './schemas'
|
||||
import type { PersonId } from './schemas'
|
||||
import type { SortType } from './schemas'
|
||||
export interface GetPersonDetails {
|
||||
person_id?: PersonId
|
||||
username?: string
|
||||
sort?: SortType
|
||||
page?: number
|
||||
limit?: number
|
||||
community_id?: CommunityId
|
||||
saved_only?: boolean
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { CommentView } from './schemas'
|
||||
import type { CommunityModeratorView } from './schemas'
|
||||
import type { PersonView } from './schemas'
|
||||
import type { PostView } from './schemas'
|
||||
import type { Site } from './schemas'
|
||||
export interface GetPersonDetailsResponse {
|
||||
person_view: PersonView
|
||||
site?: Site
|
||||
comments: Array<CommentView>
|
||||
posts: Array<PostView>
|
||||
moderates: Array<CommunityModeratorView>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { CommentSortType } from './schemas'
|
||||
export interface GetPersonMentions {
|
||||
sort?: CommentSortType
|
||||
page?: number
|
||||
limit?: number
|
||||
unread_only?: boolean
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PersonMentionView } from './schemas'
|
||||
export interface GetPersonMentionsResponse {
|
||||
mentions: Array<PersonMentionView>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { CommentId } from './schemas'
|
||||
import type { PostId } from './schemas'
|
||||
export interface GetPost {
|
||||
id?: PostId
|
||||
comment_id?: CommentId
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { CommunityModeratorView } from './schemas'
|
||||
import type { CommunityView } from './schemas'
|
||||
import type { PostView } from './schemas'
|
||||
export interface GetPostResponse {
|
||||
post_view: PostView
|
||||
community_view: CommunityView
|
||||
moderators: Array<CommunityModeratorView>
|
||||
cross_posts: Array<PostView>
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { CommunityId } from './schemas'
|
||||
import type { ListingType } from './schemas'
|
||||
import type { PaginationCursor } from './schemas'
|
||||
import type { SortType } from './schemas'
|
||||
export interface GetPosts {
|
||||
type_?: ListingType
|
||||
sort?: SortType
|
||||
page?: number
|
||||
limit?: number
|
||||
community_id?: CommunityId
|
||||
community_name?: string
|
||||
saved_only?: boolean
|
||||
liked_only?: boolean
|
||||
disliked_only?: boolean
|
||||
show_hidden?: boolean
|
||||
show_read?: boolean
|
||||
show_nsfw?: boolean
|
||||
page_cursor?: PaginationCursor
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { PaginationCursor } from './schemas'
|
||||
import type { PostView } from './schemas'
|
||||
export interface GetPostsResponse {
|
||||
posts: Array<PostView>
|
||||
next_page?: PaginationCursor
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { PersonId } from './schemas'
|
||||
export interface GetPrivateMessages {
|
||||
unread_only?: boolean
|
||||
page?: number
|
||||
limit?: number
|
||||
creator_id?: PersonId
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PersonId } from './schemas'
|
||||
export interface GetRegistrationApplication {
|
||||
person_id: PersonId
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { CommentSortType } from './schemas'
|
||||
export interface GetReplies {
|
||||
sort?: CommentSortType
|
||||
page?: number
|
||||
limit?: number
|
||||
unread_only?: boolean
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommentReplyView } from './schemas'
|
||||
export interface GetRepliesResponse {
|
||||
replies: Array<CommentReplyView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommunityId } from './schemas'
|
||||
export interface GetReportCount {
|
||||
community_id?: CommunityId
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { CommunityId } from './schemas'
|
||||
export interface GetReportCountResponse {
|
||||
community_id?: CommunityId
|
||||
comment_reports: number
|
||||
post_reports: number
|
||||
private_message_reports?: number
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface GetSiteMetadata {
|
||||
url: string;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { LinkMetadata } from './schemas'
|
||||
export interface GetSiteMetadataResponse {
|
||||
metadata: LinkMetadata
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type {
|
||||
CustomEmojiView,
|
||||
Language,
|
||||
LanguageId,
|
||||
LocalSiteUrlBlocklist,
|
||||
MyUserInfo,
|
||||
PersonView,
|
||||
SiteView,
|
||||
Tagline,
|
||||
} from '..'
|
||||
|
||||
export interface GetSiteResponse {
|
||||
site_view: SiteView
|
||||
admins: Array<PersonView>
|
||||
version: string
|
||||
my_user?: MyUserInfo
|
||||
all_languages: Array<Language>
|
||||
discussion_languages: Array<LanguageId>
|
||||
taglines: Array<Tagline>
|
||||
custom_emojis: Array<CustomEmojiView>
|
||||
blocked_urls: Array<LocalSiteUrlBlocklist>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface GetUnreadCountResponse {
|
||||
replies: number;
|
||||
mentions: number;
|
||||
private_messages: number;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface GetUnreadRegistrationApplicationCountResponse {
|
||||
registration_applications: number;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { VoteView } from './schemas'
|
||||
export interface ListCommentLikesResponse {
|
||||
comment_likes: Array<VoteView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommentReportView } from './schemas'
|
||||
export interface ListCommentReportsResponse {
|
||||
comment_reports: Array<CommentReportView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { CommunityView } from './schemas'
|
||||
export interface ListCommunitiesResponse {
|
||||
communities: Array<CommunityView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { LocalImageView } from './schemas'
|
||||
export interface ListMediaResponse {
|
||||
images: Array<LocalImageView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { VoteView } from './schemas'
|
||||
export interface ListPostLikesResponse {
|
||||
post_likes: Array<VoteView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PostReportView } from './schemas'
|
||||
export interface ListPostReportsResponse {
|
||||
post_reports: Array<PostReportView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PrivateMessageReportView } from './schemas'
|
||||
export interface ListPrivateMessageReportsResponse {
|
||||
private_message_reports: Array<PrivateMessageReportView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { RegistrationApplicationView } from './schemas'
|
||||
export interface ListRegistrationApplicationsResponse {
|
||||
registration_applications: Array<RegistrationApplicationView>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface LoginResponse {
|
||||
jwt?: string;
|
||||
registration_created: boolean;
|
||||
verify_email_sent: boolean;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PersonMentionView } from './schemas'
|
||||
export interface PersonMentionResponse {
|
||||
person_mention_view: PersonMentionView
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PostReportView } from './schemas'
|
||||
export interface PostReportResponse {
|
||||
post_report_view: PostReportView
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PostView } from './schemas'
|
||||
export interface PostResponse {
|
||||
post_view: PostView
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PrivateMessageReportView } from './schemas'
|
||||
export interface PrivateMessageReportResponse {
|
||||
private_message_report_view: PrivateMessageReportView
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PrivateMessageView } from './schemas'
|
||||
export interface PrivateMessageResponse {
|
||||
private_message_view: PrivateMessageView
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PrivateMessageView } from './schemas'
|
||||
export interface PrivateMessagesResponse {
|
||||
private_messages: Array<PrivateMessageView>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { RegistrationApplicationView } from './schemas'
|
||||
export interface RegistrationApplicationResponse {
|
||||
registration_application: RegistrationApplicationView
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface ResolveObjectResponse {
|
||||
comment?: CommentView
|
||||
post?: PostView
|
||||
community?: CommunityView
|
||||
person?: PersonView
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { CommentView } from './schemas'
|
||||
import type { CommunityView } from './schemas'
|
||||
import type { PersonView } from './schemas'
|
||||
import type { PostView } from './schemas'
|
||||
import type { SearchType } from './schemas'
|
||||
export interface SearchResponse {
|
||||
type_: SearchType
|
||||
comments: Array<CommentView>
|
||||
posts: Array<PostView>
|
||||
communities: Array<CommunityView>
|
||||
users: Array<PersonView>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { SiteView } from './schemas'
|
||||
import type { Tagline } from './schemas'
|
||||
export interface SiteResponse {
|
||||
site_view: SiteView
|
||||
taglines: Array<Tagline>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface SuccessResponse {
|
||||
success: boolean;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface UpdateTotpResponse {
|
||||
enabled: boolean;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import type { Community, ListingType } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import type { Community, ListingType } from '$lib/client/types'
|
||||
import { MenuButton, Search } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, ServerStack, XCircle } from 'svelte-hero-icons'
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import type { LocalImage, Person } from 'lemmy-js-client'
|
||||
import type { LocalImage, Person } from '$lib/client/types'
|
||||
import { action, Button, modal, toast } from 'mono-svelte'
|
||||
import { ArrowDownTray, Icon, Trash } from 'svelte-hero-icons'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { userLink } from '$lib/lemmy/generic'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import type { PersonView, SiteView, Tagline } from 'lemmy-js-client'
|
||||
import type { PersonView, SiteView, Tagline } from '$lib/client/types'
|
||||
import { Badge } from 'mono-svelte'
|
||||
import {
|
||||
BuildingOffice,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { deleteItem, save } from '$lib/lemmy/contentview.js'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import type { CommentView } from 'lemmy-js-client'
|
||||
import type { CommentView } from '$lib/client/types'
|
||||
import { Button, Menu, MenuButton } from 'mono-svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient, site } from '$lib/lemmy.svelte.js'
|
||||
import { getClient, site } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { placeholders } from '$lib/util.svelte.js'
|
||||
import type { CommentResponse } from 'lemmy-js-client'
|
||||
import type { CommentResponse } from '$lib/client/types'
|
||||
import { Button, Menu, MenuButton, toast } from 'mono-svelte'
|
||||
import { Icon, Language, XMark } from 'svelte-hero-icons'
|
||||
import type { ClassValue, HTMLTextareaAttributes } from 'svelte/elements'
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import type { CommentView } from 'lemmy-js-client'
|
||||
import type { CommentView } from '$lib/client/types'
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import type { Post } from '$lib/client/types'
|
||||
import type { CommentNodeI } from './comments.svelte'
|
||||
import Comments from './CommentTree.svelte'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import type { Post } from '$lib/client/types'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
|
||||
import Comment from './Comment.svelte'
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/lemmy.svelte'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { buttonColor, toast } from 'mono-svelte'
|
||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import type { Comment, CommentView } from 'lemmy-js-client'
|
||||
import type { Comment, CommentView } from '$lib/client/types'
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
|
||||
export interface CommentNodeI {
|
||||
|
||||
@@ -67,28 +67,31 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { client, getClient } from '$lib/client/lemmy.svelte'
|
||||
import type { CommunityModeratorView, CommunityView } from '$lib/client/types'
|
||||
import {
|
||||
amMod,
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { userLink } from '$lib/lemmy/generic'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
|
||||
import {
|
||||
action,
|
||||
Button,
|
||||
Menu,
|
||||
MenuButton,
|
||||
Modal,
|
||||
modal,
|
||||
removeToast,
|
||||
Spinner,
|
||||
@@ -105,10 +108,10 @@
|
||||
NoSymbol,
|
||||
Plus,
|
||||
ShieldCheck,
|
||||
Tag,
|
||||
} from 'svelte-hero-icons'
|
||||
import ItemList from '../generic/ItemList.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
import CommunityFlair from './CommunityFlair.svelte'
|
||||
|
||||
let loading = $state({
|
||||
blocking: false,
|
||||
@@ -135,6 +138,10 @@
|
||||
|
||||
loading.subscribing = false
|
||||
}
|
||||
|
||||
|
||||
let setFlair = $state(false)
|
||||
|
||||
interface Props {
|
||||
community_view: CommunityView | Promise<CommunityView>
|
||||
moderators?: CommunityModeratorView[]
|
||||
@@ -148,6 +155,7 @@
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
|
||||
{#await community_view}
|
||||
<div
|
||||
class="w-full h-full grid place-items-center"
|
||||
@@ -157,6 +165,9 @@
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{:then community_view}
|
||||
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||
<CommunityFlair community={community_view.community.id} onsubmit={() => setFlair = !setFlair} />
|
||||
</Modal>
|
||||
<aside
|
||||
class={[
|
||||
'min-w-full pt-0 text-slate-600 dark:text-zinc-400 flex flex-col gap-1',
|
||||
@@ -210,6 +221,14 @@
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{#if client().setFlair}
|
||||
<SidebarButton
|
||||
onclick={() => setFlair = !setFlair}
|
||||
rounding="xl"
|
||||
icon={Tag}
|
||||
label={$t('cards.community.flair')}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
||||
<SidebarButton
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Button, TextInput, toast } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
flair?: string
|
||||
community: number
|
||||
onsubmit?: (flair: string) => void
|
||||
}
|
||||
|
||||
let { flair: passedFlair = '', community, onsubmit }: Props = $props()
|
||||
let flair = $state(passedFlair)
|
||||
let loading = $state(false)
|
||||
|
||||
async function submit() {
|
||||
try {
|
||||
loading = true
|
||||
if (!client().setFlair) throw new Error('unsupported')
|
||||
|
||||
await client().setFlair!({ community_id: community, flair_text: flair })
|
||||
|
||||
onsubmit?.(flair)
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err as string),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
onsubmit={e => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
class="contents"
|
||||
>
|
||||
<TextInput bind:value={flair} label={$t('nav.commands.content')} required />
|
||||
<Button {loading} submit color="primary" size="lg">
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
@@ -6,7 +6,7 @@
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient, site } from '$lib/lemmy.svelte.js'
|
||||
import { getClient, site } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import {
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
CommunityAggregates,
|
||||
CommunityModeratorView,
|
||||
SubscribedType,
|
||||
} from 'lemmy-js-client'
|
||||
import { action, Button, Menu, MenuButton, modal, toast } from 'mono-svelte'
|
||||
} from '$lib/client/types'
|
||||
import { action, Button, Menu, MenuButton, Modal, modal, toast } from 'mono-svelte'
|
||||
import {
|
||||
BuildingOffice2,
|
||||
Check,
|
||||
@@ -26,11 +26,13 @@
|
||||
NoSymbol,
|
||||
Plus,
|
||||
ShieldCheck,
|
||||
Tag,
|
||||
} from 'svelte-hero-icons'
|
||||
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
||||
import ItemList from '../generic/ItemList.svelte'
|
||||
import { amMod, isAdmin } from '../moderation/moderation'
|
||||
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
||||
import CommunityFlair from './CommunityFlair.svelte'
|
||||
|
||||
interface Props {
|
||||
community: Community
|
||||
@@ -55,8 +57,15 @@
|
||||
compact,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let setFlair = $state(false)
|
||||
</script>
|
||||
|
||||
|
||||
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||
<CommunityFlair community={community.id} onsubmit={() => setFlair = !setFlair} />
|
||||
</Modal>
|
||||
|
||||
<EntityHeader
|
||||
{...rest}
|
||||
{compact}
|
||||
@@ -157,6 +166,10 @@
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Subscribe>
|
||||
|
||||
<Button size="custom" class="h-9 aspect-square" rounding="pill" onclick={() => setFlair = !setFlair} aria-label={$t('cards.community.flair')}>
|
||||
<Icon src={Tag} size="16" micro />
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.user && profile.current.user.moderates
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
|
||||
import type { CommunityView } from 'lemmy-js-client'
|
||||
import type { CommunityView } from '$lib/client/types'
|
||||
import { Button, modal } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { communityLink } from '$lib/lemmy/generic'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
import type { Community } from '$lib/client/types'
|
||||
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||
import type { HTMLAnchorAttributes } from 'svelte/elements'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
import type { Community } from '$lib/client/types'
|
||||
|
||||
interface Props {
|
||||
community: Community
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { searchParam } from '$lib/util.svelte'
|
||||
import { Select } from 'mono-svelte'
|
||||
import {
|
||||
ChartBar,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
MapPin,
|
||||
@@ -14,6 +15,8 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import type { SelectProps } from 'mono-svelte/forms/select/Select.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { PiefedClient } from '$lib/client/piefed/piefed'
|
||||
|
||||
interface Props extends SelectProps<string> {
|
||||
selected: string
|
||||
@@ -49,6 +52,11 @@
|
||||
<Option value="All" icon={GlobeAmericas}>
|
||||
{$t('filter.location.all')}
|
||||
</Option>
|
||||
{#if client() instanceof PiefedClient}
|
||||
<Option value="Popular" icon={ChartBar}>
|
||||
{$t('filter.location.popular')}
|
||||
</Option>
|
||||
{/if}
|
||||
<Option value="Local" icon={MapPin}>{$t('filter.location.local')}</Option>
|
||||
<Option
|
||||
value="Subscribed"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { LemmyClient } from '$lib/client/lemmy/lemmy'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { searchParam } from '$lib/util.svelte.js'
|
||||
import { Select } from 'mono-svelte'
|
||||
@@ -72,18 +74,20 @@
|
||||
<Option value="New" icon={Star}>
|
||||
{$t('filter.sort.new')}
|
||||
</Option>
|
||||
<Option value="Old" icon={Clock}>
|
||||
{$t('filter.sort.old')}
|
||||
</Option>
|
||||
<Option value="Controversial" icon={ArrowTrendingDown}>
|
||||
{$t('filter.sort.controversial')}
|
||||
</Option>
|
||||
<Option value="MostComments" icon={ChatBubbleOvalLeft}>
|
||||
{$t('filter.sort.mostcomments')}
|
||||
</Option>
|
||||
<Option value="NewComments" icon={ChatBubbleLeftRight}>
|
||||
{$t('filter.sort.newcomments')}
|
||||
</Option>
|
||||
{#if client() instanceof LemmyClient}
|
||||
<Option value="Old" icon={Clock}>
|
||||
{$t('filter.sort.old')}
|
||||
</Option>
|
||||
<Option value="Controversial" icon={ArrowTrendingDown}>
|
||||
{$t('filter.sort.controversial')}
|
||||
</Option>
|
||||
<Option value="MostComments" icon={ChatBubbleOvalLeft}>
|
||||
{$t('filter.sort.mostcomments')}
|
||||
</Option>
|
||||
<Option value="NewComments" icon={ChatBubbleLeftRight}>
|
||||
{$t('filter.sort.newcomments')}
|
||||
</Option>
|
||||
{/if}
|
||||
</Select>
|
||||
{#if selected?.startsWith('Top')}
|
||||
<Select
|
||||
|
||||
Loaded 100 of 215 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user