mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
cleanup apis, sync apis with tauri
This commit is contained in:
1 parent
e7238bdbb4
commit
e0d3bcbd05
8 files changed
+67
-138
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { GetAppInfo } from "@storyteller/tauri-api";
|
||||
import { StorytellerApiHostStore } from "@storyteller/api";
|
||||
|
||||
const SYNC_THRESHOLD = 10 * 1000;
|
||||
|
||||
class Cache {
|
||||
private static instance: Cache;
|
||||
private lastFetchSuccess?: number;
|
||||
|
||||
public static getInstance(): Cache {
|
||||
if (Cache.instance !== undefined) {
|
||||
return Cache.instance;
|
||||
}
|
||||
const instance = new Cache();
|
||||
Cache.instance = instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public canCall() : boolean {
|
||||
if (this.lastFetchSuccess === undefined) {
|
||||
return true;
|
||||
}
|
||||
return Date.now() - this.lastFetchSuccess > SYNC_THRESHOLD;
|
||||
}
|
||||
|
||||
public setCallSuccess() {
|
||||
this.lastFetchSuccess = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
export const SyncStorytellerApiConfig = async () => {
|
||||
console.log("SyncStorytellerApiConfig()")
|
||||
|
||||
const cache = Cache.getInstance();
|
||||
if (!cache.canCall()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GetAppInfo().then((appInfo) => {
|
||||
console.log("SyncStorytellerApiConfig() - appInfo", appInfo);
|
||||
const schemeAndHost = appInfo.payload.storyteller_host;
|
||||
if (!schemeAndHost) {
|
||||
return ;
|
||||
}
|
||||
console.log(`Updating hostname to ${schemeAndHost}`);
|
||||
StorytellerApiHostStore.getInstance().setApiSchemeAndHost(schemeAndHost);
|
||||
cache.setCallSuccess();
|
||||
});
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
export const apiHost = "https://api.storyteller.ai";
|
||||
|
||||
// Upload File
|
||||
export const uploadMedia = `${apiHost}/v1/media_files/upload`;
|
||||
|
||||
// Scenes
|
||||
export const uploadNewScene = `${apiHost}/v1/media_files/upload/new_scene`;
|
||||
export const uploadThumbnail = `${apiHost}/v1/media_files/cover_image/`;
|
||||
export const updateExistingScene = (sceneToken: string) =>
|
||||
`${apiHost}/v1/media_files/upload/saved_scene/${sceneToken}`;
|
||||
@@ -10,7 +10,7 @@ import "@fortawesome/fontawesome-svg-core/styles.css";
|
||||
import { config } from "@fortawesome/fontawesome-svg-core";
|
||||
import EnvironmentVariables from "~/Classes/EnvironmentVariables";
|
||||
import { pageHeight, pageWidth, persistLogin } from "~/signals";
|
||||
|
||||
import { SyncStorytellerApiConfig } from "./api/SyncStorytellerApiConfig";
|
||||
import { posthog } from "posthog-js";
|
||||
|
||||
config.autoAddCss = false; /* eslint-disable import/first */
|
||||
@@ -25,7 +25,12 @@ const ENV = {
|
||||
};
|
||||
|
||||
const GlobalSettingsManager = ({ env }: { env: Record<string, string> }) => {
|
||||
console.log("GlobalSettingsManager()");
|
||||
|
||||
SyncStorytellerApiConfig();
|
||||
|
||||
useSignals();
|
||||
|
||||
useSignalEffect(() => {
|
||||
persistLogin();
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
uploadNewScene as uploadNewSceneEndpoint,
|
||||
updateExistingScene as updateExistingSceneEndpoint,
|
||||
} from "~/api";
|
||||
import { FetchProxy as fetch } from "@storyteller/tauri-utils";
|
||||
import { StorytellerApiHostStore } from "@storyteller/api";
|
||||
|
||||
export const uploadNewScene = async (file: File, sceneTitle: string) => {
|
||||
const endpoint = uploadNewSceneEndpoint;
|
||||
const apiSchemeAndHost = StorytellerApiHostStore.getInstance().getApiSchemeAndHost();
|
||||
const endpoint = `${apiSchemeAndHost}/v1/media_files/upload/new_scene`;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("uuid_idempotency_token", uuidv4());
|
||||
formData.append("file", file);
|
||||
@@ -36,7 +35,8 @@ export const uploadNewScene = async (file: File, sceneTitle: string) => {
|
||||
};
|
||||
|
||||
export const updateExistingScene = async (file: File, sceneToken: string) => {
|
||||
const endpoint = updateExistingSceneEndpoint(sceneToken);
|
||||
const apiSchemeAndHost = StorytellerApiHostStore.getInstance().getApiSchemeAndHost();
|
||||
const endpoint = `${apiSchemeAndHost}/v1/media_files/upload/saved_scene/${sceneToken}`;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("uuid_idempotency_token", uuidv4());
|
||||
|
||||
@@ -3,7 +3,6 @@ import * as THREE from "three";
|
||||
import { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
|
||||
import { signalScene, startPollingActiveJobs } from "~/signals";
|
||||
import { updateExistingScene, uploadNewScene } from "./api_fetchers";
|
||||
import { uploadThumbnail } from "~/api";
|
||||
import environmentVariables from "~/Classes/EnvironmentVariables";
|
||||
import { GetCdnOrigin } from "~/api/GetCdnOrigin";
|
||||
import { StorytellerApiHostStore } from "@storyteller/api";
|
||||
@@ -164,7 +163,9 @@ export class APIManager {
|
||||
|
||||
if (image_resp["media_file_token"]) {
|
||||
const image_token = image_resp["media_file_token"];
|
||||
await fetch(uploadThumbnail + uploadSceneResponse["media_file_token"], {
|
||||
const endpoint = `${this.getApiSchemeAndHost()}/v1/media_files/cover_image/${uploadSceneResponse["media_file_token"]}`;
|
||||
|
||||
await fetch(endpoint, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
@@ -183,8 +184,7 @@ export class APIManager {
|
||||
public async loadSceneState(
|
||||
scene_media_file_token: string | null,
|
||||
): Promise<any> {
|
||||
const api_base_url = environmentVariables.values.BASE_API;
|
||||
const url = `${api_base_url}/v1/media_files/file/${scene_media_file_token}`;
|
||||
const url = `${this.getApiSchemeAndHost()}/v1/media_files/file/${scene_media_file_token}`;
|
||||
const response = await fetch(url);
|
||||
if (response.status > 200) {
|
||||
throw new APIManagerResponseError("Failed to load scene");
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
https://api.fakeyou.com/v1/media_files/batch?tokens=m_jh74zz1nfj2jxrkw7n00yamt32zrhb&tokens=m_0rqwx4kbnn2gz5s37apzftkw25vkzb&tokens=m_je04hbk7bqjdq9cnegp1j10mf4dzdb
|
||||
{
|
||||
"success": true,
|
||||
"media_files": [
|
||||
{
|
||||
"token": "m_0rqwx4kbnn2gz5s37apzftkw25vkzb",
|
||||
"media_type": "video",
|
||||
"media_class": "unknown",
|
||||
"maybe_media_subtype": null,
|
||||
"maybe_engine_extension": null,
|
||||
"maybe_batch_token": null,
|
||||
"public_bucket_path": "/media/c/0/n/g/p/c0ngp9c570w66q3vhs0ygmwpasf2sfk1/videoc0ngp9c570w66q3vhs0ygmwpasf2sfk1mp4",
|
||||
"maybe_model_weight_info": null,
|
||||
"maybe_creator_user": {
|
||||
"user_token": "U:937C1VN0S5G8H",
|
||||
"username": "echelon",
|
||||
"display_name": "echelon",
|
||||
"gravatar_hash": "37e7e18f19d8f654a1ace405c846a9de",
|
||||
"default_avatar": {
|
||||
"image_index": 10,
|
||||
"color_index": 3
|
||||
}
|
||||
},
|
||||
"creator_set_visibility": "private",
|
||||
"maybe_text_transcript": null,
|
||||
"maybe_prompt_token": "prompt_3sf5p1n7g3sna6pc44nqgpvyd",
|
||||
"maybe_original_filename": null,
|
||||
"is_emulated_media_file": false,
|
||||
"stats": {
|
||||
"positive_rating_count": 0,
|
||||
"bookmark_count": 0
|
||||
},
|
||||
"created_at": "2024-03-25T02:25:18Z",
|
||||
"updated_at": "2024-03-25T02:25:18Z"
|
||||
},
|
||||
{
|
||||
"token": "m_je04hbk7bqjdq9cnegp1j10mf4dzdb",
|
||||
"media_type": "video",
|
||||
"media_class": "unknown",
|
||||
"maybe_media_subtype": null,
|
||||
"maybe_engine_extension": null,
|
||||
"maybe_batch_token": null,
|
||||
"public_bucket_path": "/media/d/a/3/b/6/da3b640rh3zjj1easv96vc4d7v4jq8c1/da3b640rh3zjj1easv96vc4d7v4jq8c1.mp4",
|
||||
"maybe_model_weight_info": null,
|
||||
"maybe_creator_user": {
|
||||
"user_token": "U:937C1VN0S5G8H",
|
||||
"username": "echelon",
|
||||
"display_name": "echelon",
|
||||
"gravatar_hash": "37e7e18f19d8f654a1ace405c846a9de",
|
||||
"default_avatar": {
|
||||
"image_index": 10,
|
||||
"color_index": 3
|
||||
}
|
||||
},
|
||||
"creator_set_visibility": "public",
|
||||
"maybe_text_transcript": null,
|
||||
"maybe_prompt_token": null,
|
||||
"maybe_original_filename": null,
|
||||
"is_emulated_media_file": false,
|
||||
"stats": {
|
||||
"positive_rating_count": 0,
|
||||
"bookmark_count": 0
|
||||
},
|
||||
"created_at": "2024-03-25T02:04:22Z",
|
||||
"updated_at": "2024-03-25T02:04:22Z"
|
||||
},
|
||||
{
|
||||
"token": "m_jh74zz1nfj2jxrkw7n00yamt32zrhb",
|
||||
"media_type": "video",
|
||||
"media_class": "unknown",
|
||||
"maybe_media_subtype": null,
|
||||
"maybe_engine_extension": null,
|
||||
"maybe_batch_token": null,
|
||||
"public_bucket_path": "/media/a/c/s/z/e/acszeddd464edypg9hcp5cga0482sjfv/videoacszeddd464edypg9hcp5cga0482sjfvmp4",
|
||||
"maybe_model_weight_info": null,
|
||||
"maybe_creator_user": {
|
||||
"user_token": "U:937C1VN0S5G8H",
|
||||
"username": "echelon",
|
||||
"display_name": "echelon",
|
||||
"gravatar_hash": "37e7e18f19d8f654a1ace405c846a9de",
|
||||
"default_avatar": {
|
||||
"image_index": 10,
|
||||
"color_index": 3
|
||||
}
|
||||
},
|
||||
"creator_set_visibility": "private",
|
||||
"maybe_text_transcript": null,
|
||||
"maybe_prompt_token": "prompt_dc8x82w2gqsvbpmp5ksxypssj",
|
||||
"maybe_original_filename": null,
|
||||
"is_emulated_media_file": false,
|
||||
"stats": {
|
||||
"positive_rating_count": 0,
|
||||
"bookmark_count": 0
|
||||
},
|
||||
"created_at": "2024-03-25T02:12:46Z",
|
||||
"updated_at": "2024-03-25T02:12:46Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// lip sync will be generated through TTS
|
||||
async get_media_url() {
|
||||
//This is for prod when we have the proper info on the url.
|
||||
let api_base_url = environmentVariables.value.BASE_API;
|
||||
let url = ${api_base_url}/v1/media_files/file/${this.media_id}
|
||||
let responce = await fetch(url);
|
||||
let json = await JSON.parse(await responce.text());
|
||||
let bucketPath = json["media_file"]["public_bucket_path"];
|
||||
let media_base_url = "https://storage.googleapis.com/vocodes-public"
|
||||
let media_url = ${media_base_url}${bucketPath}
|
||||
return media_url;
|
||||
}
|
||||
https://storage.googleapis.com/vocodes-public
|
||||
@@ -1,2 +0,0 @@
|
||||
mkdir /User/ChromeData
|
||||
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/User/ChromeData" --disable-web-security
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
//const DEFAULT_API_HOST = "https://api.storyteller.ai";
|
||||
const DEFAULT_API_HOST = "http://localhost:12345";
|
||||
//const DEFAULT_API_HOST = "http://localhost:12345";
|
||||
const DEFAULT_API_HOST = "https://api.storyteller.ai";
|
||||
|
||||
export class StorytellerApiHostStore {
|
||||
private static instance: StorytellerApiHostStore;
|
||||
|
||||
Reference in new issue
Block a user