Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lemm.ee as default lemmy instance #1745

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/App/VoyagerWatch Watch App/WatchSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import WatchConnectivity
class WatchSessionManager: NSObject, ObservableObject {
static let shared = WatchSessionManager()

@Published var connectedInstance = "lemmy.world" // Variable to hold connected server hostname (optional)
@Published var connectedInstance = "lemm.ee" // Variable to hold connected server hostname (optional)
@Published var authToken: String? // Variable to hold the auth token (optional)

var loggedIn: Bool {
Expand Down
2 changes: 1 addition & 1 deletion src/features/auth/authSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ updateApplicationContextIfNeeded(getCredentialsFromStorage());
function updateApplicationContextIfNeeded(
accounts: CredentialStoragePayload | undefined,
) {
const DEFAULT_INSTANCE = "lemmy.world";
const DEFAULT_INSTANCE = "lemm.ee";

const connectedInstance = (() => {
if (!accounts) return DEFAULT_INSTANCE;
Expand Down
8 changes: 5 additions & 3 deletions src/features/shared/markdown/editing/uploadImageSlice.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { UploadImageResponse } from "lemmy-js-client";

import { clientSelector } from "#/features/auth/authSelectors";
import { clientSelector, urlSelector } from "#/features/auth/authSelectors";
import { _uploadImage } from "#/services/lemmy";
import { AppDispatch, RootState } from "#/store";

Expand Down Expand Up @@ -44,9 +44,11 @@ export default uploadImageSlice.reducer;

export const uploadImage =
(image: File) => async (dispatch: AppDispatch, getState: () => RootState) => {
const client = clientSelector(getState());
const state = getState();
const client = clientSelector(state);
const url = urlSelector(state);

const response = await _uploadImage(client, image);
const response = await _uploadImage(url, client, image);

dispatch(onUploadedImage(response));

Expand Down
2 changes: 1 addition & 1 deletion src/services/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";

import { isNative } from "#/helpers/device";

const DEFAULT_LEMMY_SERVERS = getCustomDefaultServers() ?? ["lemmy.world"];
const DEFAULT_LEMMY_SERVERS = getCustomDefaultServers() ?? ["lemm.ee"];

let _customServers = DEFAULT_LEMMY_SERVERS;

Expand Down
39 changes: 33 additions & 6 deletions src/services/lemmy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,47 @@ export function getClient(url: string, jwt?: string): LemmyHttp {

export const LIMIT = 50;

interface CustomLimit {
maxFileSize: number;
maxWidth: number;
maxHeight: number;
}

const CUSTOM_LIMITS: Record<string, CustomLimit> = {
["lemm.ee"]: {
maxFileSize: 490_000, // 490 kB
maxWidth: 1200,
maxHeight: 1200,
},
};

// Lemmy default is 1MB
const DEFAULT_LIMIT: CustomLimit = {
maxFileSize: 990_000, // 990 kB
maxWidth: 1500,
maxHeight: 1500,
};

/**
* upload image, compressing before upload if needed
*
* @returns relative pictrs URL
*/
export async function _uploadImage(client: LemmyHttp, image: File) {
export async function _uploadImage(
instance: string,
client: LemmyHttp,
image: File,
) {
let compressedImageIfNeeded;

const limits = CUSTOM_LIMITS[instance] ?? DEFAULT_LIMIT;

try {
compressedImageIfNeeded = await reduceFileSize(
image,
990_000, // 990 kB - Lemmy's default limit is 1MB
1500,
1500,
limits.maxFileSize,
limits.maxWidth,
limits.maxHeight,
0.85,
);
} catch (error) {
Expand All @@ -53,8 +80,8 @@ export async function _uploadImage(client: LemmyHttp, image: File) {
});

// lemm.ee uses response.message for error messages (e.g. account too new)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!response.url) throw new Error(response.msg ?? (response as any).message);
if (!response.url)
throw new Error(response.msg ?? (response as unknown as Error).message);

return response;
}
Expand Down