Feature/download click listen (#578)

Co-authored-by: Michael Chung <michaelchung@michaels-mbp-2.home>
This commit is contained in:
ArEnScandMichael Chung authored and GitHub committed 2025-05-02 18:06:17 -04:00
1 parent 3f94e48f12
commit df8d999ed7
18 files changed
+415 -58

No files matched your search

Generated
+31
View File
@@ -9401,6 +9401,17 @@ dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "read-progress-stream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6435842fc2fea44b528719eb8c32203bbc1bb2f5b619fbe0c0a3d8350fd8d2a8"
dependencies = [
"bytes 1.10.0",
"futures 0.3.29",
"pin-project-lite",
]
[[package]]
name = "realfft"
version = "3.4.0"
@@ -12136,6 +12147,7 @@ dependencies = [
"tauri-build",
"tauri-plugin-http",
"tauri-plugin-log",
"tauri-plugin-upload",
"tempdir",
"tempfile",
"tokens",
@@ -12292,6 +12304,25 @@ dependencies = [
"time",
]
[[package]]
name = "tauri-plugin-upload"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e90ac6d3a783d4406caeae8c75aa05e96346474765517fddfd1dc313ff91aa89"
dependencies = [
"futures-util",
"log",
"read-progress-stream",
"reqwest 0.12.15",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.12",
"tokio",
"tokio-util",
]
[[package]]
name = "tauri-realtime"
version = "0.1.0"
+4
View File
@@ -67,6 +67,10 @@ tauri-plugin-http = { path = "../../vendor/tauri-plugin-http" }
# types and can't do threading. We need to wait for a new version to unpin from Git.
discord-rich-presence = { git = "https://github.com/vionya/discord-rich-presence" }
objc2-web-kit = "0.3.1"
objc2-app-kit = "0.3.1"
tauri-plugin-upload = "2.2.1"
[dev-dependencies]
libloading = "0.8.6"
serial_test = "3.2.0"
@@ -8,13 +8,23 @@
"permissions": [
"core:default",
"log:default",
"upload:allow-download",
"upload:default",
{
"identifier": "http:default",
"allow": [
{ "url": "https://*.storyteller.ai" },
{ "url": "https://*.fakeyou.com" }
{
"url": "https://*.storyteller.ai"
},
{
"url": "https://*.fakeyou.com"
}
],
"deny": [{ "url": "https://private.tauri.app" }]
"deny": [
{
"url": "https://private.tauri.app"
}
]
}
]
}
+1
View File
@@ -54,6 +54,7 @@ pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_upload::init())
.plugin(tauri_plugin_log::Builder::new()
.level(log::LevelFilter::Info)
.targets(vec![
@@ -279,26 +279,26 @@ export class EditEngine {
public async setupStage() {
// Frame rate inicator
const textNode = new Konva.Text({
x: 10,
y: 80,
text: "",
fontSize: 18,
fontFamily: "Source Sans 3",
fill: "white",
});
const anim = new Konva.Animation((frame) => {
if (frame && import.meta.env.DEV) {
const timeDiff = frame.timeDiff;
const frameRate = frame.frameRate;
textNode.setText(
`FrameTime: ${timeDiff.toFixed(0)} ms\nFrameRate: ${frameRate.toFixed(0)} fps`,
);
}
}, this.mediaLayer);
// const textNode = new Konva.Text({
// x: 10,
// y: 80,
// text: "",
// fontSize: 18,
// fontFamily: "Source Sans 3",
// fill: "white",
// });
// const anim = new Konva.Animation((frame) => {
// if (frame && import.meta.env.DEV) {
// const timeDiff = frame.timeDiff;
// const frameRate = frame.frameRate;
// textNode.setText(
// `FrameTime: ${timeDiff.toFixed(0)} ms\nFrameRate: ${frameRate.toFixed(0)} fps`,
// );
// }
// }, this.mediaLayer);
anim.start();
this.uiLayer.add(textNode);
// anim.start();
// this.uiLayer.add(textNode);
this.addKeyboardShortcuts();
}
+19 -19
View File
@@ -561,26 +561,26 @@ export class Engine {
public async setupStage() {
// Frame rate inicator
const textNode = new Konva.Text({
x: 10,
y: 80,
text: "",
fontSize: 18,
fontFamily: "Source Sans 3",
fill: "white",
});
const anim = new Konva.Animation((frame) => {
if (frame && import.meta.env.DEV) {
const timeDiff = frame.timeDiff;
const frameRate = frame.frameRate;
textNode.setText(
`FrameTime: ${timeDiff.toFixed(0)} ms\nFrameRate: ${frameRate.toFixed(0)} fps`,
);
}
}, this.mediaLayer);
// const textNode = new Konva.Text({
// x: 10,
// y: 80,
// text: "",
// fontSize: 18,
// fontFamily: "Source Sans 3",
// fill: "white",
// });
// const anim = new Konva.Animation((frame) => {
// if (frame && import.meta.env.DEV) {
// const timeDiff = frame.timeDiff;
// const frameRate = frame.frameRate;
// textNode.setText(
// `FrameTime: ${timeDiff.toFixed(0)} ms\nFrameRate: ${frameRate.toFixed(0)} fps`,
// );
// }
// }, this.mediaLayer);
anim.start();
this.uiLayer.add(textNode);
// anim.start();
//this.uiLayer.add(textNode);
this.addKeyboardShortcuts();
}
@@ -3,7 +3,7 @@ import { invoke } from "@tauri-apps/api/core";
import { useSignals } from "@preact/signals-react/runtime";
import { toast } from "sonner";
import { UploaderStates, uploadImage } from "~/components/UploadImage";
import { downloadFileFromUrl } from "@storyteller/api";
import { PopoverMenu } from "~/components/reusable/Popover";
import { Tooltip } from "@storyteller/ui-tooltip";
import { Button } from "@storyteller/ui-button";
@@ -33,6 +33,7 @@ import { useJobContext } from "~/components/JobContext";
import { IsDesktopApp } from "@storyteller/tauri-utils";
import { GalleryItem, GalleryModal } from "@storyteller/ui-gallery-modal";
import { PromptsApi } from "@storyteller/api";
interface ReferenceImage {
id: string;
url: string;
@@ -357,6 +358,7 @@ export const PromptBox = () => {
}
};
return (
<>
<Modal
@@ -536,6 +538,7 @@ export const PromptBox = () => {
]}
activeTab={activeGalleryTab}
onTabChange={setActiveGalleryTab}
onDownloadClicked={downloadFileFromUrl}
/>
</>
);
@@ -8,10 +8,13 @@ import { useState } from "react";
import { AuthButtons } from "~/components/shared_authentication/AuthButtons";
import { Tooltip } from "@storyteller/ui-tooltip";
import { downloadFileFromUrl } from "@storyteller/api";
export const ToolbarTopRight = () => {
const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false);
const [isGalleryModalOpen, setIsGalleryModalOpen] = useState(false);
const [activeGalleryTab, setActiveGalleryTab] = useState("my-media");
return (
<>
@@ -50,6 +53,7 @@ export const ToolbarTopRight = () => {
]}
activeTab={activeGalleryTab}
onTabChange={setActiveGalleryTab}
onDownloadClicked={downloadFileFromUrl}
/>
</>
);
@@ -14,7 +14,7 @@ import { Activity } from "~/pages/PageEnigma/comps/GenerateModals/Activity";
import { GalleryModal } from "@storyteller/ui-gallery-modal";
import { SettingsModal } from "@storyteller/ui-settings-modal";
import { Tooltip } from "@storyteller/ui-tooltip";
import { downloadFileFromUrl } from "@storyteller/api";
function isEditorPath(path: string) {
if (path === "/") return true;
if (path === "/idealenigma/") return true;
@@ -116,6 +116,7 @@ export const TopBar = ({ pageName }: Props) => {
]}
activeTab={activeLibraryTab}
onTabChange={setActiveLibraryTab}
onDownloadClicked={downloadFileFromUrl}
/>
</>
);
@@ -4,6 +4,7 @@ import { invoke } from "@tauri-apps/api/core";
import { EngineContext } from "~/pages/PageEnigma/contexts/EngineContext";
import { IsDesktopApp } from "@storyteller/tauri-utils";
import { uploadImage } from "~/components/reusable/UploadModalMedia/uploadImage";
import { downloadFileFromUrl } from "@storyteller/api";
import {
faPlus,
faCamera,
@@ -880,6 +881,7 @@ export const PromptBox = () => {
]}
activeTab={activeGalleryTab}
onTabChange={setActiveGalleryTab}
onDownloadClicked={downloadFileFromUrl}
/>
</>
);
+4 -2
View File
@@ -15,5 +15,7 @@
"default": "./dist/index.js"
}
},
"dependencies": {}
}
"dependencies": {
"@tauri-apps/plugin-upload": "2.2.1"
}
}
+1 -3
View File
@@ -1,14 +1,12 @@
export * from "./lib/enums/index.js";
export * from "./lib/AnalyticsApi.js";
export * from "./lib/BillingApi.js";
export * from "./lib/CommentsApi.js";
export * from "./lib/EngineApi.js";
export * from "./lib/FeaturedItemsApi.js";
export * from "./lib/JobsApi.js";
export * from "./lib/MediaFilesApi.js";
export * from "./lib/MediaUploadApi.js";
export * from "./lib/MiscApi.js";
export * from "./lib/ModerationApi.js";
export * from "./lib/LocalApi.js";
export * from "./lib/PromptsApi.js";
export * from "./lib/TtsApi.js";
export * from "./lib/UserBookmarksApi.js";
+29
View File
@@ -0,0 +1,29 @@
import { download } from "@tauri-apps/plugin-upload";
import { downloadDir } from "@tauri-apps/api/path";
export const downloadFileFromUrl = async (url: string) => {
console.log("GOT THE URL", url);
try {
// Extract filename from URL
const urlObj = new URL(url);
let filename = urlObj.pathname.split("/").pop();
if (!filename || filename === "") {
filename = "downloaded_file";
}
// Get downloads directory path
const downloadsPath = await downloadDir();
const filePath = `${downloadsPath}/${filename}`;
// Download and save the file
await download(url, filePath);
console.log(
`File downloaded and saved as ${filename} in downloads folder`,
);
} catch (error) {
console.error("Error downloading file:", error);
throw error;
}
};
@@ -39,6 +39,7 @@ interface GalleryModalProps {
tabs: { id: string; label: string }[];
activeTab: string;
onTabChange: (tabId: string) => void;
onDownloadClicked?: (url: string) => Promise<void>;
}
export const GalleryModal = React.memo(
@@ -53,6 +54,7 @@ export const GalleryModal = React.memo(
tabs,
activeTab,
onTabChange,
onDownloadClicked,
}: GalleryModalProps) => {
const [groupedItems, setGroupedItems] = useState<GroupedItems>({});
const [loading, setLoading] = useState(false);
@@ -337,6 +339,7 @@ export const GalleryModal = React.memo(
title={lightboxImage?.label}
createdAt={lightboxImage?.createdAt}
downloadUrl={imageUrl}
onDownloadClicked={onDownloadClicked}
/>
</>
);
@@ -15,6 +15,7 @@ interface LightboxModalProps {
createdAt?: string;
additionalInfo?: React.ReactNode;
downloadUrl?: string;
onDownloadClicked?: (url: string) => Promise<void>;
}
export function LightboxModal({
@@ -27,6 +28,7 @@ export function LightboxModal({
createdAt,
additionalInfo,
downloadUrl,
onDownloadClicked,
}: LightboxModalProps) {
return createPortal(
<Transition appear show={isOpen}>
@@ -96,19 +98,26 @@ export function LightboxModal({
</div>
{downloadUrl && (
<div className="flex justify-end">
<a
href={downloadUrl}
download
onClick={(e) => e.stopPropagation()}
className="no-underline"
>
{onDownloadClicked ? (
<Button
icon={faDownToLine}
onClick={(e) => e.stopPropagation()}
onClick={async (e) => {
e.stopPropagation();
await onDownloadClicked(downloadUrl);
}}
>
Download
</Button>
</a>
) : (
<a
href={downloadUrl}
download
onClick={(e) => e.stopPropagation()}
className="no-underline"
>
<Button icon={faDownToLine}>Download</Button>
</a>
)}
</div>
)}
</div>
+13 -1
View File
@@ -2178,7 +2178,10 @@
},
"libs/api": {
"name": "@storyteller/api",
"version": "0.0.1"
"version": "0.0.1",
"dependencies": {
"@tauri-apps/plugin-upload": "2.2.1"
}
},
"libs/components/button": {
"name": "@storyteller/ui-button",
@@ -11142,6 +11145,15 @@
"@tauri-apps/api": "^2.0.0"
}
},
"node_modules/@tauri-apps/plugin-upload": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-upload/-/plugin-upload-2.2.1.tgz",
"integrity": "sha512-2EyVhJYLAp2mJH0UzO3QGU0vPk/YWvAfdI2wXbczyzEZY/AZVa9wConyB1TV/NGhyJRim4LwWgkmnEvcKLkECw==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.0.0"
}
},
"node_modules/@techstark/opencv-js": {
"version": "4.10.0-release.1",
"resolved": "https://registry.npmjs.org/@techstark/opencv-js/-/opencv-js-4.10.0-release.1.tgz",
+246 -1
View File
@@ -2,5 +2,250 @@
"name": "storyteller-rust",
"lockfileVersion": 3,
"requires": true,
"packages": {}
"packages": {
"": {
"dependencies": {
"@tauri-apps/plugin-upload": "^2.2.1"
},
"devDependencies": {
"@tauri-apps/cli": "^2.5.0"
}
},
"node_modules/@tauri-apps/api": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.5.0.tgz",
"integrity": "sha512-Ldux4ip+HGAcPUmuLT8EIkk6yafl5vK0P0c0byzAKzxJh7vxelVtdPONjfgTm96PbN24yjZNESY8CKo8qniluA==",
"license": "Apache-2.0 OR MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/tauri"
}
},
"node_modules/@tauri-apps/cli": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-2.5.0.tgz",
"integrity": "sha512-rAtHqG0Gh/IWLjN2zTf3nZqYqbo81oMbqop56rGTjrlWk9pTTAjkqOjSL9XQLIMZ3RbeVjveCqqCA0s8RnLdMg==",
"dev": true,
"license": "Apache-2.0 OR MIT",
"bin": {
"tauri": "tauri.js"
},
"engines": {
"node": ">= 10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/tauri"
},
"optionalDependencies": {
"@tauri-apps/cli-darwin-arm64": "2.5.0",
"@tauri-apps/cli-darwin-x64": "2.5.0",
"@tauri-apps/cli-linux-arm-gnueabihf": "2.5.0",
"@tauri-apps/cli-linux-arm64-gnu": "2.5.0",
"@tauri-apps/cli-linux-arm64-musl": "2.5.0",
"@tauri-apps/cli-linux-riscv64-gnu": "2.5.0",
"@tauri-apps/cli-linux-x64-gnu": "2.5.0",
"@tauri-apps/cli-linux-x64-musl": "2.5.0",
"@tauri-apps/cli-win32-arm64-msvc": "2.5.0",
"@tauri-apps/cli-win32-ia32-msvc": "2.5.0",
"@tauri-apps/cli-win32-x64-msvc": "2.5.0"
}
},
"node_modules/@tauri-apps/cli-darwin-arm64": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.5.0.tgz",
"integrity": "sha512-VuVAeTFq86dfpoBDNYAdtQVLbP0+2EKCHIIhkaxjeoPARR0sLpFHz2zs0PcFU76e+KAaxtEtAJAXGNUc8E1PzQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-darwin-x64": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.5.0.tgz",
"integrity": "sha512-hUF01sC06cZVa8+I0/VtsHOk9BbO75rd+YdtHJ48xTdcYaQ5QIwL4yZz9OR1AKBTaUYhBam8UX9Pvd5V2/4Dpw==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-arm-gnueabihf": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.5.0.tgz",
"integrity": "sha512-LQKqttsK252LlqYyX8R02MinUsfFcy3+NZiJwHFgi5Y3+ZUIAED9cSxJkyNtuY5KMnR4RlpgWyLv4P6akN1xhg==",
"cpu": [
"arm"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-arm64-gnu": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.5.0.tgz",
"integrity": "sha512-mTQufsPcpdHg5RW0zypazMo4L55EfeE5snTzrPqbLX4yCK2qalN7+rnP8O8GT06xhp6ElSP/Ku1M2MR297SByQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-arm64-musl": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.5.0.tgz",
"integrity": "sha512-rQO1HhRUQqyEaal5dUVOQruTRda/TD36s9kv1hTxZiFuSq3558lsTjAcUEnMAtBcBkps20sbyTJNMT0AwYIk8Q==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-riscv64-gnu": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-riscv64-gnu/-/cli-linux-riscv64-gnu-2.5.0.tgz",
"integrity": "sha512-7oS18FN46yDxyw1zX/AxhLAd7T3GrLj3Ai6s8hZKd9qFVzrAn36ESL7d3G05s8wEtsJf26qjXnVF4qleS3dYsA==",
"cpu": [
"riscv64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-x64-gnu": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.5.0.tgz",
"integrity": "sha512-SG5sFNL7VMmDBdIg3nO3EzNRT306HsiEQ0N90ILe3ZABYAVoPDO/ttpCO37ApLInTzrq/DLN+gOlC/mgZvLw1w==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-x64-musl": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.5.0.tgz",
"integrity": "sha512-QXDM8zp/6v05PNWju5ELsVwF0VH1n6b5pk2E6W/jFbbiwz80Vs1lACl9pv5kEHkrxBj+aWU/03JzGuIj2g3SkQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-win32-arm64-msvc": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.5.0.tgz",
"integrity": "sha512-pFSHFK6b+o9y4Un8w0gGLwVyFTZaC3P0kQ7umRt/BLDkzD5RnQ4vBM7CF8BCU5nkwmEBUCZd7Wt3TWZxe41o6Q==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-win32-ia32-msvc": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.5.0.tgz",
"integrity": "sha512-EArv1IaRlogdLAQyGlKmEqZqm5RfHCUMhJoedWu7GtdbOMUfSAz6FMX2boE1PtEmNO4An+g188flLeVErrxEKg==",
"cpu": [
"ia32"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-win32-x64-msvc": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.5.0.tgz",
"integrity": "sha512-lj43EFYbnAta8pd9JnUq87o+xRUR0odz+4rixBtTUwUgdRdwQ2V9CzFtsMu6FQKpFQ6mujRK6P1IEwhL6ADRsQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0 OR MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/plugin-upload": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-upload/-/plugin-upload-2.2.1.tgz",
"integrity": "sha512-2EyVhJYLAp2mJH0UzO3QGU0vPk/YWvAfdI2wXbczyzEZY/AZVa9wConyB1TV/NGhyJRim4LwWgkmnEvcKLkECw==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.0.0"
}
}
}
}
+3
View File
@@ -1,5 +1,8 @@
{
"devDependencies": {
"@tauri-apps/cli": "^2.5.0"
},
"dependencies": {
"@tauri-apps/plugin-upload": "^2.2.1"
}
}