Новая система вложений
This commit is contained in:
@@ -7,7 +7,7 @@ import { useConsoleLogger } from "@/app/hooks/useConsoleLogger";
|
||||
interface TransportContextValue {
|
||||
transportServer: string | null;
|
||||
uploadFile: (id: string, content: string) => Promise<any>;
|
||||
downloadFile: (id: string, tag: string) => Promise<string>;
|
||||
downloadFile: (id: string, tag: string, transportServer: string) => Promise<string>;
|
||||
uploading: TransportState[];
|
||||
downloading: TransportState[];
|
||||
}
|
||||
@@ -86,14 +86,14 @@ export function TransportProvider(props: TransportProviderProps) {
|
||||
* @param tag тег файла
|
||||
* @param chachaDecryptedKey ключ для расшифровки файла
|
||||
*/
|
||||
const downloadFile = (id: string, tag : string) : Promise<string> => {
|
||||
const downloadFile = (id: string, tag : string, transportServer: string) : Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!transportServerRef.current) {
|
||||
if (!transportServer) {
|
||||
throw new Error("Transport server is not set");
|
||||
}
|
||||
setDownloading(prev => [...prev, { id: id, progress: 0 }]);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', `${transportServerRef.current}/d/${tag}`);
|
||||
xhr.open('GET', `${transportServer}/d/${tag}`);
|
||||
xhr.responseType = 'text';
|
||||
|
||||
xhr.onprogress = (event) => {
|
||||
|
||||
12
app/providers/TransportProvider/useTransportServer.ts
Normal file
12
app/providers/TransportProvider/useTransportServer.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useContext } from "react";
|
||||
import { TransportContext } from "./TransportProvider";
|
||||
|
||||
export function useTransportServer() {
|
||||
const context = useContext(TransportContext);
|
||||
if(!context){
|
||||
throw new Error("useTransportServer must be used within a TransportProvider");
|
||||
}
|
||||
const { transportServer } = context;
|
||||
|
||||
return transportServer;
|
||||
}
|
||||
Reference in New Issue
Block a user