mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Add basic download support on the web
This commit is contained in:
parent
213d5b74b5
commit
883f39e4b5
@ -27,7 +27,7 @@ import Download from "@material-symbols/svg-400/rounded/download.svg";
|
|||||||
import { WatchStatusV, queryFn, useAccount } from "@kyoo/models";
|
import { WatchStatusV, queryFn, useAccount } from "@kyoo/models";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { watchListIcon } from "./watchlist-info";
|
import { watchListIcon } from "./watchlist-info";
|
||||||
import { useDownloader } from "../downloads/state";
|
import { useDownloader } from "../downloads";
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
import { useYoshiki } from "yoshiki/native";
|
import { useYoshiki } from "yoshiki/native";
|
||||||
|
|
||||||
|
@ -19,4 +19,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export { DownloadPage } from "./page";
|
export { DownloadPage } from "./page";
|
||||||
export { DownloadProvider } from "./state";
|
export { DownloadProvider, useDownloader } from "./state";
|
||||||
|
48
front/packages/ui/src/downloads/index.web.tsx
Normal file
48
front/packages/ui/src/downloads/index.web.tsx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Kyoo - A portable and vast media library solution.
|
||||||
|
* Copyright (c) Kyoo.
|
||||||
|
*
|
||||||
|
* See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||||
|
*
|
||||||
|
* Kyoo is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* Kyoo is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { WatchInfo, kyooApiUrl, queryFn, toQueryKey } from "@kyoo/models";
|
||||||
|
import { Player } from "../player";
|
||||||
|
import { getCurrentAccount } from "@kyoo/models/src/account-internal";
|
||||||
|
|
||||||
|
export const useDownloader = () => {
|
||||||
|
return async (type: "episode" | "movie", slug: string) => {
|
||||||
|
const account = getCurrentAccount();
|
||||||
|
const query = Player.infoQuery(type, slug);
|
||||||
|
const info: WatchInfo = await queryFn(
|
||||||
|
{
|
||||||
|
queryKey: toQueryKey(query),
|
||||||
|
signal: undefined as any,
|
||||||
|
meta: undefined,
|
||||||
|
apiUrl: account?.apiUrl,
|
||||||
|
},
|
||||||
|
query.parser,
|
||||||
|
account?.token.access_token,
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: This methods does not work with auth.
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.style.display = "none";
|
||||||
|
a.href = `${kyooApiUrl}/video/${type}/${slug}/direct`;
|
||||||
|
a.download = `${slug}.${info.extension}`;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
};
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user