fix: memory leak on file web stream fix

This commit is contained in:
2024-03-16 21:29:29 +07:00
parent cc66501d43
commit b7c1ceb2b3
9 changed files with 148 additions and 102 deletions
+3 -9
View File
@@ -1,13 +1,14 @@
import FileList, { FileItem } from "@/components/pages/files/FileList";
import { useAsyncStorage } from "@/hooks/useAsyncStorage";
import api from "@/lib/api";
import authStore, { useAuth } from "@/stores/authStore";
import { useAuth } from "@/stores/authStore";
import BackButton from "@ui/BackButton";
import Box from "@ui/Box";
import Input from "@ui/Input";
import { Stack } from "expo-router";
import React from "react";
import { useQuery } from "react-query";
import { openFile } from "./utils";
const FilesPage = () => {
const { isLoggedIn } = useAuth();
@@ -49,7 +50,7 @@ const FilesPage = () => {
return setParams({ ...params, path: file.path });
}
downloadFile(file);
openFile(file);
}}
canGoBack={parentPath != null}
/>
@@ -57,11 +58,4 @@ const FilesPage = () => {
);
};
async function downloadFile(file: FileItem) {
const url = api.files.download.$url();
url.searchParams.set("path", file.path);
url.searchParams.set("token", authStore.getState().token);
window.open(url.toString(), "_blank");
}
export default FilesPage;
+15
View File
@@ -0,0 +1,15 @@
import { FileItem } from "@/components/pages/files/FileList";
import { API_BASEURL } from "@/lib/constants";
import authStore from "@/stores/authStore";
export function openFile(file: FileItem, dl = false) {
const url = getFileUrl(file, dl);
window.open(url, "_blank");
}
export function getFileUrl(file: FileItem, dl = false) {
const url = new URL(API_BASEURL + "/files/download" + file.path);
url.searchParams.set("token", authStore.getState().token);
dl && url.searchParams.set("dlmode", "true");
return url.toString();
}
+3 -3
View File
@@ -7,8 +7,8 @@ import Box from "@ui/Box";
import Text from "@ui/Text";
import React, { useEffect, useRef } from "react";
import "xterm/css/xterm.css";
import { API_BASEURL } from "@/lib/constants";
import authStore, { useAuth } from "@/stores/authStore";
import { BASEURL } from "@/lib/constants";
import { useAuth } from "@/stores/authStore";
import { Stack } from "expo-router";
import BackButton from "@ui/BackButton";
@@ -28,7 +28,7 @@ const TerminalPage = () => {
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
const baseUrl = API_BASEURL.replace("https://", "wss://").replace(
const baseUrl = BASEURL.replace("https://", "wss://").replace(
"http://",
"ws://"
);
+2 -1
View File
@@ -13,7 +13,7 @@ import { useMutation } from "react-query";
import api from "@/lib/api";
import Alert from "@ui/Alert";
import { setAuthToken } from "@/stores/authStore";
import { router } from "expo-router";
import { Stack, router } from "expo-router";
const schema = z.object({
username: z.string().min(1),
@@ -44,6 +44,7 @@ const LoginPage = () => {
<ScrollView
contentContainerStyle={cn("flex-1 flex items-center justify-center")}
>
<Stack.Screen options={{ headerShown: false }} />
<Container className="p-4">
<Box className="p-8 bg-white rounded-lg">
<Text className="text-2xl">Login</Text>
+1 -1
View File
@@ -10,7 +10,7 @@ import type {
import type { AppType } from "../../backend/routes/_routes";
import authStore, { logout } from "@/stores/authStore";
const api: ReturnType<typeof hono<AppType>> = hc(API_BASEURL + "/api", {
const api: ReturnType<typeof hono<AppType>> = hc(API_BASEURL, {
fetch: fetchHandler,
});
+3 -1
View File
@@ -1,3 +1,5 @@
export const API_BASEURL = __DEV__
export const BASEURL = __DEV__
? "http://localhost:3000"
: location.protocol + "//" + location.host;
export const API_BASEURL = BASEURL + "/api";