feat: add v0.19.0 support
This commit is contained in:
1 parent
b3b8a10e44
commit
119ab53946
62 files changed
+188
-157
No files matched your search
+3
-1
@@ -1,7 +1,9 @@
|
||||
function buildUrl(inputUrl: URL): URL {
|
||||
let withoutCors = inputUrl.pathname.replace('/cors/', '')
|
||||
|
||||
if (!withoutCors.startsWith('https://')) {
|
||||
if (
|
||||
!(withoutCors.startsWith('https://') || withoutCors.startsWith('http://'))
|
||||
) {
|
||||
withoutCors = 'https://' + withoutCors
|
||||
}
|
||||
|
||||
|
||||
+35
-18
@@ -1,15 +1,16 @@
|
||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import { client, getClient, site } from '$lib/lemmy.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { moveItem } from '$lib/util.js'
|
||||
import { instanceToURL, moveItem } from '$lib/util.js'
|
||||
import {
|
||||
LemmyHttp,
|
||||
type GetSiteResponse,
|
||||
type MyUserInfo,
|
||||
} from 'lemmy-js-client'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||
|
||||
const getDefaultProfile = (): Profile => ({
|
||||
id: -1,
|
||||
@@ -87,13 +88,21 @@ profile.subscribe(async (p) => {
|
||||
instance.set(p.instance)
|
||||
// fetch the user because p.user is undefined
|
||||
const user = await userFromJwt(p.jwt, p.instance)
|
||||
.then((user) => {
|
||||
if (!user?.user)
|
||||
toast({
|
||||
content: 'Your login has expired. Re-login to fix this issue.',
|
||||
type: 'warning',
|
||||
})
|
||||
site.set(user?.site)
|
||||
|
||||
if (!user?.user)
|
||||
toast({
|
||||
content: 'Your login has expired. Re-login to fix this issue.',
|
||||
type: 'warning',
|
||||
return user
|
||||
})
|
||||
site.set(user?.site)
|
||||
.catch((err) => {
|
||||
toast({ content: err as any, type: 'error' })
|
||||
})
|
||||
|
||||
if (!user?.user) return
|
||||
|
||||
profile.update(() => ({
|
||||
...p,
|
||||
@@ -105,13 +114,17 @@ profile.subscribe(async (p) => {
|
||||
|
||||
export async function setUser(jwt: string, inst: string, username: string) {
|
||||
try {
|
||||
new URL(`https://${inst}`)
|
||||
new URL(instanceToURL(inst))
|
||||
} catch (err) {
|
||||
return
|
||||
}
|
||||
|
||||
const user = await userFromJwt(jwt, inst)
|
||||
if (!user) {
|
||||
.then((u) => u)
|
||||
.catch((err) => {
|
||||
toast({ content: err as any, type: 'error' })
|
||||
})
|
||||
if (!user?.user) {
|
||||
toast({
|
||||
content: 'Failed to fetch your user. Is your instance down?',
|
||||
type: 'error',
|
||||
@@ -152,9 +165,7 @@ async function userFromJwt(
|
||||
jwt: string,
|
||||
instance: string
|
||||
): Promise<{ user: PersonData; site: GetSiteResponse } | undefined> {
|
||||
const sitePromise = getClient(instance).getSite({
|
||||
auth: jwt,
|
||||
})
|
||||
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
|
||||
|
||||
let timer = setTimeout(
|
||||
() =>
|
||||
@@ -170,6 +181,12 @@ async function userFromJwt(
|
||||
return r
|
||||
})
|
||||
|
||||
if (!versionIsSupported(site.version, MINIMUM_VERSION)) {
|
||||
throw new Error(
|
||||
`This version of Photon only supports Lemmy instances with version ${MINIMUM_VERSION} or higher. This Lemmy instance is running: ${site.version}`
|
||||
)
|
||||
}
|
||||
|
||||
const myUser = site.my_user
|
||||
if (!myUser) return undefined
|
||||
|
||||
@@ -250,6 +267,10 @@ export async function setUserID(id: number) {
|
||||
|
||||
if (prof?.jwt) {
|
||||
const user = await userFromJwt(prof.jwt, prof.instance)
|
||||
.then((u) => u)
|
||||
.catch((err) => {
|
||||
toast({ content: err as any, type: 'error' })
|
||||
})
|
||||
instance.set(prof.instance)
|
||||
prof.user = user?.user
|
||||
prof.avatar = user?.user.local_user_view.person.avatar
|
||||
@@ -276,16 +297,12 @@ export function moveProfile(id: number, up: boolean) {
|
||||
}
|
||||
|
||||
const getNotificationCount = async (jwt: string, mod: boolean) => {
|
||||
const unreads = await getClient().getUnreadCount({
|
||||
auth: jwt,
|
||||
})
|
||||
const unreads = await getClient().getUnreadCount()
|
||||
|
||||
let reports: number = 0
|
||||
|
||||
if (mod) {
|
||||
const reportRes = await getClient().getReportCount({
|
||||
auth: jwt,
|
||||
})
|
||||
const reportRes = await getClient().getReportCount({})
|
||||
|
||||
reports =
|
||||
reportRes.comment_reports +
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
search={async (q) => {
|
||||
const results = await getClient().search({
|
||||
q: q || ' ',
|
||||
auth: jwt,
|
||||
type_: 'Communities',
|
||||
limit: 20,
|
||||
listing_type: listing_type,
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
try {
|
||||
await getClient().editComment({
|
||||
auth: $profile.jwt,
|
||||
comment_id: node.comment_view.comment.id,
|
||||
content: newComment,
|
||||
})
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
try {
|
||||
const response = await getClient().createComment({
|
||||
auth: $profile.jwt,
|
||||
content: value,
|
||||
post_id: postId,
|
||||
parent_id: parentId,
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
await getClient()
|
||||
.likeComment({
|
||||
score: upvoted ? 0 : 1,
|
||||
auth: $profile.jwt,
|
||||
comment_id: commentId,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
@@ -59,7 +58,6 @@
|
||||
await getClient()
|
||||
.likeComment({
|
||||
score: upvoted ? 0 : -1,
|
||||
auth: $profile.jwt,
|
||||
comment_id: commentId,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
parent.loading = true
|
||||
|
||||
const newComments = await getClient($page.params.instance).getComments({
|
||||
auth: $profile?.jwt,
|
||||
max_depth: 5,
|
||||
parent_id: parent.comment_view.comment.id,
|
||||
type_: 'All',
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
try {
|
||||
await getClient().followCommunity({
|
||||
auth: $profile.jwt,
|
||||
community_id: community_view.community.id,
|
||||
follow: !subscribed,
|
||||
})
|
||||
@@ -61,7 +60,6 @@
|
||||
|
||||
try {
|
||||
await getClient().blockCommunity({
|
||||
auth: $profile.jwt,
|
||||
community_id: community_view.community.id,
|
||||
block: !blocked,
|
||||
})
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
|
||||
const res = edit
|
||||
? await getClient().editCommunity({
|
||||
auth: $profile.jwt,
|
||||
title: formData.displayName,
|
||||
description: formData.sidebar,
|
||||
nsfw: formData.nsfw,
|
||||
@@ -59,7 +58,6 @@
|
||||
community_id: edit,
|
||||
})
|
||||
: await getClient().createCommunity({
|
||||
auth: $profile.jwt,
|
||||
name: formData.name,
|
||||
title: formData.displayName,
|
||||
description: formData.sidebar,
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
try {
|
||||
await getClient().createPrivateMessage({
|
||||
auth: $profile.jwt,
|
||||
content: message,
|
||||
recipient_id: user.id,
|
||||
})
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
|
||||
if (community) {
|
||||
await getClient().banFromCommunity({
|
||||
auth: $profile.jwt,
|
||||
ban: !banned,
|
||||
community_id: community.id,
|
||||
person_id: item.id,
|
||||
@@ -72,7 +71,6 @@
|
||||
})
|
||||
} else {
|
||||
await getClient().banPerson({
|
||||
auth: $profile.jwt,
|
||||
ban: !banned,
|
||||
person_id: item.id,
|
||||
reason: reason || undefined,
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
try {
|
||||
await getClient().lockPost({
|
||||
auth: $profile.jwt,
|
||||
locked: lock,
|
||||
post_id: item.post.id,
|
||||
})
|
||||
@@ -60,7 +59,6 @@
|
||||
try {
|
||||
await getClient().featurePost({
|
||||
feature_type: toInstance ? 'Local' : 'Community',
|
||||
auth: $profile.jwt,
|
||||
featured: pinned,
|
||||
post_id: item.post.id,
|
||||
})
|
||||
|
||||
@@ -57,13 +57,11 @@
|
||||
if (purge) {
|
||||
if (isCommentView(item)) {
|
||||
await getClient(undefined, fetch).purgeComment({
|
||||
auth: $profile.jwt,
|
||||
comment_id: item.comment.id,
|
||||
reason: reason,
|
||||
})
|
||||
} else {
|
||||
await getClient(undefined, fetch).purgePost({
|
||||
auth: $profile.jwt,
|
||||
post_id: item.post.id,
|
||||
reason: reason,
|
||||
})
|
||||
@@ -91,7 +89,6 @@
|
||||
if (privateMessage) {
|
||||
await getClient()
|
||||
.createPrivateMessage({
|
||||
auth: $profile.jwt,
|
||||
content: replyReason,
|
||||
recipient_id: isCommentView(item)
|
||||
? item.comment.creator_id
|
||||
@@ -106,7 +103,6 @@
|
||||
} else {
|
||||
await getClient()
|
||||
.createComment({
|
||||
auth: $profile.jwt,
|
||||
content: replyReason,
|
||||
post_id: item.post.id,
|
||||
parent_id: isCommentView(item) ? item.comment.id : undefined,
|
||||
@@ -122,7 +118,6 @@
|
||||
|
||||
if (isCommentView(item)) {
|
||||
await getClient().removeComment({
|
||||
auth: $profile.jwt,
|
||||
comment_id: item.comment.id,
|
||||
removed: !removed,
|
||||
reason: reason || undefined,
|
||||
@@ -130,7 +125,6 @@
|
||||
item.comment.removed = !removed
|
||||
} else if (isPostView(item)) {
|
||||
await getClient().removePost({
|
||||
auth: $profile.jwt,
|
||||
post_id: item.post.id,
|
||||
removed: !removed,
|
||||
reason: reason || undefined,
|
||||
|
||||
@@ -27,13 +27,11 @@
|
||||
try {
|
||||
if (isComment(item)) {
|
||||
await getClient().createCommentReport({
|
||||
auth: $profile.jwt,
|
||||
comment_id: item.comment.id,
|
||||
reason: reason,
|
||||
})
|
||||
} else if (isPost(item)) {
|
||||
await getClient().createPostReport({
|
||||
auth: $profile.jwt,
|
||||
post_id: item.post.id,
|
||||
reason: reason,
|
||||
})
|
||||
|
||||
@@ -78,7 +78,7 @@ export const amMod = (me: MyUserInfo, community: Community) =>
|
||||
export const amModOfAny = (me?: MyUserInfo) =>
|
||||
me && (me.moderates.length > 0 || isAdmin(me))
|
||||
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.local_user.admin
|
||||
|
||||
export const removalTemplate = (
|
||||
input: string,
|
||||
|
||||
@@ -63,7 +63,6 @@
|
||||
communitySearch = passedCommunity.name
|
||||
} else {
|
||||
const list = await getClient().listCommunities({
|
||||
auth: $profile?.jwt,
|
||||
type_: 'All',
|
||||
sort: 'Active',
|
||||
limit: 40,
|
||||
@@ -107,7 +106,6 @@
|
||||
}
|
||||
|
||||
const post = await getClient().editPost({
|
||||
auth: $profile.jwt,
|
||||
name: data.title,
|
||||
body: data.body,
|
||||
url: data.url || undefined,
|
||||
@@ -121,10 +119,11 @@
|
||||
|
||||
dispatcher('submit', post.post_view)
|
||||
} else {
|
||||
let image = data.image ? await uploadImage(data.image[0], $profile.instance, $profile.jwt) : undefined
|
||||
let image = data.image
|
||||
? await uploadImage(data.image[0], $profile.instance, $profile.jwt)
|
||||
: undefined
|
||||
data.url = image || data.url || undefined
|
||||
const post = await getClient().createPost({
|
||||
auth: $profile.jwt,
|
||||
community_id: data.community!,
|
||||
name: data.title,
|
||||
body: data.body,
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||
|
||||
export const isMutable = (post: PostView, me: PersonView) =>
|
||||
(me.person.admin && post.post.local) || me.person.id == post.creator.id
|
||||
|
||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
me.person.id == comment.creator.id
|
||||
|
||||
@@ -13,8 +10,8 @@ export const bestImageURL = (
|
||||
width: number = 1024
|
||||
) => {
|
||||
if (width > 1024) {
|
||||
if (post.url) return `${post.url}?format=webp`
|
||||
else if (post.thumbnail_url) return `${post.thumbnail_url}?format=webp`
|
||||
if (post.url) return `${post.url}?format=webp`
|
||||
else if (post.thumbnail_url) return `${post.thumbnail_url}?format=webp`
|
||||
}
|
||||
|
||||
if (compact && post.thumbnail_url)
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
<Button
|
||||
href="/admin"
|
||||
aria-label="Admin"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 relative"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 "
|
||||
>
|
||||
<Icon src={CommandLine} mini size="16" slot="prefix" />
|
||||
<span class="hidden md:inline">Admin</span>
|
||||
|
||||
+31
-13
@@ -2,6 +2,8 @@ import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { instance } from '$lib/instance.js'
|
||||
import { instanceToURL } from '$lib/util.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
async function customFetch(
|
||||
func: (
|
||||
@@ -16,33 +18,49 @@ async function customFetch(
|
||||
return res
|
||||
}
|
||||
|
||||
export function client({
|
||||
instanceURL,
|
||||
func,
|
||||
auth,
|
||||
}: {
|
||||
instanceURL?: string
|
||||
func?: (
|
||||
input: RequestInfo | URL,
|
||||
init?: RequestInit | undefined
|
||||
) => Promise<Response>
|
||||
auth?: string
|
||||
}) {
|
||||
if (!instanceURL) instanceURL = get(instance)
|
||||
|
||||
let jwt = auth ? auth : get(profile)?.jwt
|
||||
|
||||
let headers = jwt ? { Authorization: `Bearer ${jwt}` } : { Authorization: '' }
|
||||
|
||||
return new LemmyHttp(instanceToURL(instanceURL), {
|
||||
fetchFunction: func,
|
||||
headers: headers,
|
||||
})
|
||||
}
|
||||
|
||||
export function getClient(
|
||||
instanceURL?: string,
|
||||
func?: (
|
||||
input: RequestInfo | URL,
|
||||
init?: RequestInit | undefined
|
||||
) => Promise<Response>
|
||||
) => Promise<Response>,
|
||||
auth?: string
|
||||
): LemmyHttp {
|
||||
if (!instanceURL) {
|
||||
instanceURL = get(instance)
|
||||
}
|
||||
|
||||
return new LemmyHttp(`https://${instanceURL}`, {
|
||||
fetchFunction: func
|
||||
? (input, init) => customFetch(func, input, init)
|
||||
: undefined,
|
||||
})
|
||||
return client({ instanceURL, func, auth })
|
||||
}
|
||||
|
||||
export const getInstance = () => get(instance)
|
||||
|
||||
export const getInstance = () => encodeURIComponent(get(instance))
|
||||
export const site = writable<GetSiteResponse | undefined>(undefined)
|
||||
|
||||
export async function validateInstance(instance: string): Promise<boolean> {
|
||||
if (instance == '') return false
|
||||
|
||||
try {
|
||||
await getClient(instance).getSite({})
|
||||
await getClient(instance).getSite()
|
||||
|
||||
return true
|
||||
} catch (err) {
|
||||
|
||||
@@ -70,7 +70,6 @@ export async function save(
|
||||
if (item.type == 'post') {
|
||||
return (
|
||||
await getClient().savePost({
|
||||
auth: jwt,
|
||||
post_id: item.id,
|
||||
save: save,
|
||||
})
|
||||
@@ -78,7 +77,6 @@ export async function save(
|
||||
} else if (item.type == 'comment') {
|
||||
return (
|
||||
await getClient().saveComment({
|
||||
auth: jwt,
|
||||
comment_id: item.id,
|
||||
save: save,
|
||||
})
|
||||
@@ -97,7 +95,6 @@ export async function deleteItem(
|
||||
if (item.type == 'post') {
|
||||
return (
|
||||
await getClient().deletePost({
|
||||
auth: jwt,
|
||||
post_id: item.id,
|
||||
deleted: deleted,
|
||||
})
|
||||
@@ -105,7 +102,6 @@ export async function deleteItem(
|
||||
} else if (item.type == 'comment') {
|
||||
return (
|
||||
await getClient().deleteComment({
|
||||
auth: jwt,
|
||||
comment_id: item.id,
|
||||
deleted: deleted,
|
||||
})
|
||||
@@ -124,7 +120,6 @@ export async function vote(
|
||||
if (item.type == 'post') {
|
||||
return (
|
||||
await getClient().likePost({
|
||||
auth: jwt,
|
||||
post_id: item.id,
|
||||
score: vote,
|
||||
})
|
||||
@@ -132,7 +127,6 @@ export async function vote(
|
||||
} else if (item.type == 'comment') {
|
||||
return (
|
||||
await getClient().likeComment({
|
||||
auth: jwt,
|
||||
comment_id: item.id,
|
||||
score: vote,
|
||||
})
|
||||
@@ -151,7 +145,6 @@ export async function markAsRead(
|
||||
if (item.type == 'post') {
|
||||
return (
|
||||
await getClient().markPostAsRead({
|
||||
auth: jwt,
|
||||
post_id: item.id,
|
||||
read: read,
|
||||
})
|
||||
|
||||
@@ -10,7 +10,6 @@ export const blockUser = async (block: boolean, id: number) => {
|
||||
if (!auth) throw new Error('Unauthorized')
|
||||
|
||||
const response = await getClient().blockPerson({
|
||||
auth: auth,
|
||||
block: block,
|
||||
person_id: id,
|
||||
})
|
||||
@@ -53,14 +52,12 @@ export const addSubscription = (
|
||||
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
|
||||
trycatch(async () => {
|
||||
const user = await getClient().resolveObject({
|
||||
auth: jwt,
|
||||
q: handle,
|
||||
})
|
||||
|
||||
if (!user.person) throw new Error('No user found')
|
||||
|
||||
return await getClient().addAdmin({
|
||||
auth: jwt,
|
||||
added: true,
|
||||
person_id: user.person.person.id,
|
||||
})
|
||||
|
||||
+9
-2
@@ -101,8 +101,10 @@ export const removeItem = <T>(array: T[], predicate: (item: T) => boolean) => {
|
||||
array.splice(array.findIndex(predicate), 1)
|
||||
}
|
||||
|
||||
export const DOMAIN_REGEX = /^((?!-)[A-Za-z0-9-]{1,63}\.)+[A-Za-z]{2,63}/gi
|
||||
export const DOMAIN_REGEX_FORMS = '^((?!-)[A-Za-z0-9-]{1,63}.)+[A-Za-z]{2,63}'
|
||||
export const DOMAIN_REGEX =
|
||||
/^(http(s)?:\/\/)?((?!-)[A-Za-z0-9-]{1,63}\.)+[A-Za-z]{2,63}(:[0-9]{0,5})$/g
|
||||
export const DOMAIN_REGEX_FORMS =
|
||||
'(http(s)?://)?((?!-)[A-Za-z0-9-]{1,63}.)+[A-Za-z]{2,63}(:[0-9]{0,5})?'
|
||||
|
||||
export const isSubscribed = (subscribed: SubscribedType) =>
|
||||
subscribed == 'Pending' || subscribed == 'Subscribed'
|
||||
@@ -166,3 +168,8 @@ export async function uploadImage(
|
||||
}: ${response.status}: ${response.statusText}`
|
||||
)
|
||||
}
|
||||
|
||||
export const instanceToURL = (input: string) =>
|
||||
input.startsWith('http://') || input.startsWith('https://')
|
||||
? input
|
||||
: `https://${input}`
|
||||
@@ -0,0 +1,31 @@
|
||||
export const MINIMUM_VERSION = '0.19.0'
|
||||
export const MAXIMUM_VERSION = '0.999'
|
||||
|
||||
export const versionIsSupported = (v: string, minimum: string) => {
|
||||
const regex = /^(\d+\.)?(\d+\.)?(\*|\d+)*/i
|
||||
const cur = v.match(regex)
|
||||
const min = minimum.match(regex)
|
||||
|
||||
if (!cur || !min) return false
|
||||
|
||||
const [minMajor, minMinor, minPatch] = min.slice(1, 4).map((i) => Number(i))
|
||||
const [curMajor, curMinor, curPatch] = cur.slice(1, 4).map((i) => Number(i))
|
||||
|
||||
if (curMajor < minMajor) {
|
||||
return false
|
||||
} else if (curMajor > minMajor) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (curMinor < minMinor) {
|
||||
return false
|
||||
} else if (curMinor > minMinor) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (curPatch < minPatch) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -25,7 +25,6 @@ export async function load({ url, fetch }) {
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: listingType,
|
||||
auth: get(profile)?.jwt,
|
||||
}),
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -8,9 +8,7 @@ export async function load({ fetch }) {
|
||||
let site = get(siteStore)
|
||||
|
||||
if (!site) {
|
||||
const res = await getClient(undefined, fetch).getSite({
|
||||
auth: jwt,
|
||||
})
|
||||
const res = await getClient(undefined, fetch).getSite()
|
||||
|
||||
site = res
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ export async function load({ data, fetch, url }) {
|
||||
const unreadOnly = (url.searchParams.get('unreadOnly') || 'true') == 'true'
|
||||
|
||||
const res = await getClient(undefined, fetch).listRegistrationApplications({
|
||||
auth: jwt,
|
||||
page: page,
|
||||
limit: 40,
|
||||
unread_only: unreadOnly,
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
try {
|
||||
await getClient().approveRegistrationApplication({
|
||||
approve: approve,
|
||||
auth: $profile.jwt,
|
||||
id: application.registration_application.id,
|
||||
})
|
||||
toast({
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
try {
|
||||
await getClient().editSite({
|
||||
auth: jwt,
|
||||
...formData,
|
||||
})
|
||||
toast({
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
if (!blocked) allowedInstances.push(instance)
|
||||
|
||||
await getClient().editSite({
|
||||
auth: $profile.jwt,
|
||||
blocked_instances: blockedInstances,
|
||||
allowed_instances: allowedInstances,
|
||||
})
|
||||
@@ -102,7 +101,6 @@
|
||||
)
|
||||
|
||||
return await getClient().editSite({
|
||||
auth: $profile.jwt,
|
||||
allowed_instances: allowedInstances,
|
||||
blocked_instances: blockedInstances,
|
||||
})
|
||||
|
||||
@@ -3,9 +3,7 @@ import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ fetch, parent }) {
|
||||
const instances = await getClient(undefined, fetch).getFederatedInstances({
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
const instances = await getClient(undefined, fetch).getFederatedInstances()
|
||||
|
||||
return {
|
||||
federated_instances: instances,
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
try {
|
||||
await getClient().editSite({
|
||||
auth: $profile.jwt,
|
||||
taglines: taglines,
|
||||
})
|
||||
toast({
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
const result = await trycatch(() =>
|
||||
getClient().addAdmin({
|
||||
added: false,
|
||||
auth: $profile!.jwt!,
|
||||
person_id: id,
|
||||
})
|
||||
)
|
||||
|
||||
@@ -19,11 +19,9 @@ export async function load(req: any) {
|
||||
community_name: req.params.name,
|
||||
page: page,
|
||||
sort: sort,
|
||||
auth: get(profile)?.jwt,
|
||||
}),
|
||||
community: getClient(undefined, req.fetch).getCommunity({
|
||||
name: req.params.name,
|
||||
auth: get(profile)?.jwt,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,11 @@
|
||||
|
||||
try {
|
||||
const res = await getClient().resolveObject({
|
||||
auth: $profile.jwt,
|
||||
q: formData.newModerator,
|
||||
})
|
||||
|
||||
if (res.person) {
|
||||
const addModRes = await getClient().addModToCommunity({
|
||||
auth: $profile.jwt,
|
||||
added: true,
|
||||
person_id: res.person.person.id,
|
||||
community_id: data.community.community_view.community.id,
|
||||
@@ -66,7 +64,6 @@
|
||||
try {
|
||||
const res = await getClient().addModToCommunity({
|
||||
added: false,
|
||||
auth: $profile.jwt,
|
||||
community_id: data.community.community_view.community.id,
|
||||
person_id: id,
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@ import { get } from 'svelte/store'
|
||||
export async function load({ params, fetch }) {
|
||||
const comment = await getClient(undefined, fetch).getComment({
|
||||
id: Number(params.id),
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
throw redirect(
|
||||
|
||||
@@ -21,7 +21,6 @@ export async function load({ url, fetch }) {
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
auth: get(profile)?.jwt,
|
||||
})),
|
||||
type: type,
|
||||
sort: sort,
|
||||
@@ -35,7 +34,6 @@ export async function load({ url, fetch }) {
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: type,
|
||||
auth: get(profile)?.jwt,
|
||||
})),
|
||||
type: type,
|
||||
sort: sort,
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
try {
|
||||
const res = await getClient().followCommunity({
|
||||
auth: $profile.jwt,
|
||||
community_id: id,
|
||||
follow: subscribed == 'NotSubscribed',
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export const load = ({ url }) => ({
|
||||
crosspost: Boolean(url.searchParams.get('crosspost')) ?? false,
|
||||
})
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
|
||||
export const load = ({ url }) => {
|
||||
return { crosspost: Boolean(url.searchParams.get('crosspost')) ?? false }
|
||||
}
|
||||
@@ -30,9 +30,7 @@
|
||||
|
||||
markingAsRead = true
|
||||
|
||||
const response = await getClient().markAllAsRead({
|
||||
auth: $profile.jwt!,
|
||||
})
|
||||
const response = await getClient().markAllAsRead()
|
||||
|
||||
$profile.user.unreads = 0
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ export async function load({ url, fetch }) {
|
||||
const params = {
|
||||
limit: 20,
|
||||
page: page,
|
||||
auth: auth.jwt,
|
||||
unread_only: unreadOnly == 'true',
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
try {
|
||||
await getClient().createPrivateMessage({
|
||||
auth: $profile.jwt,
|
||||
content: reply,
|
||||
recipient_id: message.creator.id,
|
||||
})
|
||||
@@ -68,13 +67,11 @@
|
||||
|
||||
if (item.type == 'person_mention') {
|
||||
await getClient().markPersonMentionAsRead({
|
||||
auth: $profile?.jwt,
|
||||
person_mention_id: item.id,
|
||||
read: isRead,
|
||||
})
|
||||
} else if (item.type == 'comment_reply') {
|
||||
await getClient().markCommentReplyAsRead({
|
||||
auth: $profile?.jwt,
|
||||
comment_reply_id: item.id,
|
||||
read: isRead,
|
||||
})
|
||||
|
||||
@@ -3,9 +3,6 @@ import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ fetch }) {
|
||||
return (
|
||||
await getClient(undefined, fetch).getFederatedInstances({
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
).federated_instances
|
||||
return (await getClient(undefined, fetch).getFederatedInstances())
|
||||
.federated_instances
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { setUser } from '$lib/auth.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { Note, toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
@@ -11,6 +11,8 @@
|
||||
Identification,
|
||||
QuestionMarkCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import { DOMAIN_REGEX_FORMS } from '$lib/util.js'
|
||||
import { MINIMUM_VERSION } from '$lib/version.js'
|
||||
|
||||
let data = {
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
@@ -36,10 +38,12 @@
|
||||
})
|
||||
|
||||
if (response?.jwt) {
|
||||
await setUser(response.jwt, data.instance, data.username)
|
||||
const result = await setUser(response.jwt, data.instance, data.username)
|
||||
|
||||
toast({ content: 'Successfully logged in.', type: 'success' })
|
||||
goto('/')
|
||||
if (result) {
|
||||
toast({ content: 'Successfully logged in.', type: 'success' })
|
||||
goto('/')
|
||||
}
|
||||
} else {
|
||||
throw new Error('Invalid credentials')
|
||||
}
|
||||
@@ -62,6 +66,13 @@
|
||||
<div class="flex flex-col gap-2">
|
||||
<h1 class="font-bold text-3xl">Log In</h1>
|
||||
<p>Enter the fediverse</p>
|
||||
<Note>
|
||||
This version of Photon supports instances running
|
||||
<span style="font-family: monospace;">
|
||||
v{MINIMUM_VERSION}
|
||||
</span>
|
||||
or higher.
|
||||
</Note>
|
||||
</div>
|
||||
<div class="flex flex-row w-full items-center gap-2">
|
||||
<TextInput
|
||||
@@ -81,7 +92,7 @@
|
||||
bind:value={data.instance}
|
||||
class="flex-1"
|
||||
required
|
||||
pattern={'(?!-)[A-Za-z0-9-]+([-.]{1}[a-z0-9]+)*.[A-Za-z]{2,6}'}
|
||||
pattern={DOMAIN_REGEX_FORMS}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -32,7 +32,6 @@ export async function load({ url, fetch }) {
|
||||
const client = getClient(undefined, fetch)
|
||||
|
||||
const params = {
|
||||
auth: jwt,
|
||||
limit: 20,
|
||||
page: page,
|
||||
unresolved_only: type == 'unread',
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
switch (item.type) {
|
||||
case 'comment': {
|
||||
const res = await getClient().resolveCommentReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.id,
|
||||
resolved: !item.resolved,
|
||||
})
|
||||
@@ -44,7 +43,6 @@
|
||||
}
|
||||
case 'post': {
|
||||
const res = await getClient().resolvePostReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.id,
|
||||
resolved: !item.resolved,
|
||||
})
|
||||
@@ -61,7 +59,6 @@
|
||||
}
|
||||
case 'message': {
|
||||
const res = await getClient().resolvePrivateMessageReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.id,
|
||||
resolved: !item.resolved,
|
||||
})
|
||||
@@ -79,9 +76,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
const reports = await getClient().getReportCount({
|
||||
auth: $profile?.jwt,
|
||||
})
|
||||
const reports = await getClient().getReportCount({})
|
||||
|
||||
$profile.user.reports =
|
||||
reports.comment_reports +
|
||||
|
||||
@@ -207,7 +207,6 @@ export async function load({ url }) {
|
||||
(url.searchParams.get('type') as ModlogActionType) || 'All'
|
||||
|
||||
const results = await getClient().getModlog({
|
||||
auth: get(profile)?.jwt,
|
||||
community_id: community,
|
||||
limit: 40,
|
||||
type_: type,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { instance } from '$lib/instance.js'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import { error, redirect } from '@sveltejs/kit'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -6,7 +7,7 @@ export function load({ params, url }) {
|
||||
if (Number(params.instance)) {
|
||||
const split = url.pathname.split('/')
|
||||
|
||||
split.splice(2, 0, `${get(instance)?.toLowerCase()}`)
|
||||
split.splice(2, 0, `${getInstance()?.toLowerCase()}`)
|
||||
|
||||
const newUrl = new URL(url)
|
||||
newUrl.pathname = split.join('/')
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
$profile?.jwt
|
||||
) {
|
||||
getClient().markPostAsRead({
|
||||
auth: $profile.jwt,
|
||||
read: $userSettings.markPostsAsRead,
|
||||
post_id: post.post_view.post.id,
|
||||
})
|
||||
@@ -73,7 +72,6 @@
|
||||
|
||||
try {
|
||||
const res = await getClient().resolveObject({
|
||||
auth: jwt,
|
||||
q: post.post_view.post.ap_id,
|
||||
})
|
||||
|
||||
@@ -98,7 +96,6 @@
|
||||
commentsPage = 1
|
||||
|
||||
data.streamed.comments = getClient().getComments({
|
||||
auth: $profile?.jwt,
|
||||
page: 1,
|
||||
limit: 25,
|
||||
type_: 'All',
|
||||
|
||||
@@ -8,7 +8,6 @@ import { get } from 'svelte/store'
|
||||
export async function load({ params, url, fetch }) {
|
||||
const post = await getClient(params.instance.toLowerCase(), fetch).getPost({
|
||||
id: Number(params.id),
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
let max_depth = post.post_view.counts.comments > 100 ? 1 : 3
|
||||
@@ -38,7 +37,6 @@ export async function load({ params, url, fetch }) {
|
||||
max_depth: max_depth,
|
||||
saved_only: false,
|
||||
sort: sort,
|
||||
auth: get(profile)?.jwt,
|
||||
parent_id: parentId,
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
data.person_blocks = data.person_blocks
|
||||
|
||||
await getClient().blockPerson({
|
||||
auth: $profile.jwt,
|
||||
block: false,
|
||||
person_id: item.target.id,
|
||||
})
|
||||
@@ -50,7 +49,6 @@
|
||||
data.community_blocks = data.community_blocks
|
||||
|
||||
await getClient().blockCommunity({
|
||||
auth: $profile.jwt,
|
||||
block: false,
|
||||
community_id: item.community.id,
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
newPasswordVerify = ''
|
||||
let loading = false
|
||||
|
||||
// @ts-ignore
|
||||
$: totpLink = data.my_user?.local_user_view?.local_user?.totp_2fa_url
|
||||
|
||||
async function changePassword() {
|
||||
@@ -22,7 +23,6 @@
|
||||
if (!$profile?.jwt) return
|
||||
loading = true
|
||||
const res = await getClient().changePassword({
|
||||
auth: $profile?.jwt,
|
||||
new_password: newPassword,
|
||||
new_password_verify: newPasswordVerify,
|
||||
old_password: oldPassword,
|
||||
@@ -56,8 +56,8 @@
|
||||
await getClient().saveUserSettings({
|
||||
...data.my_user?.local_user_view.local_user,
|
||||
...data.my_user?.local_user_view.person,
|
||||
// @ts-ignore
|
||||
generate_totp_2fa: enabled,
|
||||
auth: $profile?.jwt,
|
||||
})
|
||||
goto($page.url, { invalidateAll: true })
|
||||
toast({
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
: undefined
|
||||
|
||||
const res = await getClient().saveUserSettings({
|
||||
auth: $profile.jwt,
|
||||
...formData,
|
||||
avatar: pfp,
|
||||
})
|
||||
@@ -104,9 +103,10 @@
|
||||
try {
|
||||
const { jwt } = $profile
|
||||
|
||||
// TODO - add option to delete content
|
||||
await getClient().deleteAccount({
|
||||
auth: jwt,
|
||||
password: deletion.password,
|
||||
delete_content: false,
|
||||
})
|
||||
|
||||
profileData.update((pd) => {
|
||||
|
||||
@@ -5,8 +5,7 @@ import type { SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const my_user = (await getClient().getSite({ auth: get(profile)?.jwt }))
|
||||
.my_user
|
||||
const my_user = (await getClient().getSite()).my_user
|
||||
|
||||
return {
|
||||
my_user: my_user,
|
||||
|
||||
@@ -17,7 +17,6 @@ export async function load({ url, fetch, parent }) {
|
||||
page: page,
|
||||
username: my_user?.local_user_view.person.name,
|
||||
sort: sort,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
const items = [...user.posts, ...user.comments]
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { CommentSortType, CommentView, ListingType, PostView, SortType } from 'lemmy-js-client'
|
||||
import type {
|
||||
CommentSortType,
|
||||
CommentView,
|
||||
ListingType,
|
||||
PostView,
|
||||
SortType,
|
||||
} from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
function getSavedItemPublished(item: PostView | CommentView) {
|
||||
@@ -18,12 +24,11 @@ export async function load({ url, fetch }) {
|
||||
const client = getClient(undefined, fetch)
|
||||
|
||||
const params = {
|
||||
auth: get(profile)!.jwt!,
|
||||
saved_only: true,
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: 'New' as SortType & CommentSortType,
|
||||
type_: 'All' as ListingType
|
||||
type_: 'All' as ListingType,
|
||||
}
|
||||
|
||||
const [posts, comments] = await Promise.all([
|
||||
|
||||
@@ -22,7 +22,6 @@ export async function load({ url, fetch }) {
|
||||
if (query) {
|
||||
const results = await getClient(undefined, fetch).search({
|
||||
q: query,
|
||||
auth: get(profile)?.jwt,
|
||||
community_id: community ?? undefined,
|
||||
limit: 20,
|
||||
page: page,
|
||||
@@ -52,7 +51,6 @@ export async function load({ url, fetch }) {
|
||||
streamed: {
|
||||
object: get(profile)?.jwt
|
||||
? getClient(undefined, fetch).resolveObject({
|
||||
auth: get(profile)!.jwt!,
|
||||
q: query,
|
||||
})
|
||||
: undefined,
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
const blocked = isBlocked($profile.user, block)
|
||||
|
||||
await getClient().blockPerson({
|
||||
auth: $profile.jwt,
|
||||
block: !blocked,
|
||||
person_id: block,
|
||||
})
|
||||
@@ -130,7 +129,7 @@
|
||||
<div
|
||||
class="!divide-y divide-slate-200 dark:divide-zinc-800 flex flex-col"
|
||||
>
|
||||
{#each data.items as item (item.counts.id)}
|
||||
{#each data.items as item}
|
||||
{#if isCommentView(item) && (data.type == 'all' || data.type == 'comments')}
|
||||
<CommentItem comment={item} />
|
||||
{:else if !isCommentView(item) && (data.type == 'all' || data.type == 'posts')}
|
||||
|
||||
@@ -15,7 +15,6 @@ export async function load({ params, url, fetch }) {
|
||||
page: page,
|
||||
username: params.name,
|
||||
sort: sort,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
const items = [...user.posts, ...user.comments]
|
||||
|
||||
Reference in new issue
Block a user