mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-27 08:48:14 +00:00
rename storyteller api
This commit is contained in:
@@ -5,7 +5,7 @@ import * as studio from "@storyteller/studio";
|
|||||||
|
|
||||||
const mockApi = window.location.search.includes("mock-api");
|
const mockApi = window.location.search.includes("mock-api");
|
||||||
|
|
||||||
interface StorytellerApiInterface {
|
interface IStorytellerApi {
|
||||||
createScene(file: File): Promise<MediaFileToken>
|
createScene(file: File): Promise<MediaFileToken>
|
||||||
session(): Promise<Session>
|
session(): Promise<Session>
|
||||||
listMediaFiles(options: ListMediaFilesOptions): Promise<ListMediaFilesResult>
|
listMediaFiles(options: ListMediaFilesOptions): Promise<ListMediaFilesResult>
|
||||||
@@ -18,7 +18,7 @@ interface StorytellerApiInterface {
|
|||||||
mediaFile(token: MediaFileToken): Promise<MediaFile>
|
mediaFile(token: MediaFileToken): Promise<MediaFile>
|
||||||
}
|
}
|
||||||
|
|
||||||
class StorytellerApiBase implements StorytellerApiInterface {
|
class StorytellerApiBase implements IStorytellerApi {
|
||||||
#api = axios.create({
|
#api = axios.create({
|
||||||
baseURL: "https://api.fakeyou.com",
|
baseURL: "https://api.fakeyou.com",
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
@@ -137,7 +137,7 @@ interface LocalDbSchema extends DBSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StorytellerApiMock implements StorytellerApiInterface {
|
class StorytellerApiMock implements IStorytellerApi {
|
||||||
database?: IDBPDatabase<LocalDbSchema>;
|
database?: IDBPDatabase<LocalDbSchema>;
|
||||||
dateFormat: Intl.DateTimeFormat = new Intl.DateTimeFormat("en-us")
|
dateFormat: Intl.DateTimeFormat = new Intl.DateTimeFormat("en-us")
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ class StorytellerApiMock implements StorytellerApiInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class StorytellerApi implements StorytellerApiInterface {
|
export class StorytellerApi implements IStorytellerApi {
|
||||||
createScene(file: File): Promise<string> {
|
createScene(file: File): Promise<string> {
|
||||||
return this.api_base.createScene(file)
|
return this.api_base.createScene(file)
|
||||||
}
|
}
|
||||||
@@ -457,7 +457,7 @@ export class StorytellerApi implements StorytellerApiInterface {
|
|||||||
mediaFile(token: string): Promise<MediaFile> {
|
mediaFile(token: string): Promise<MediaFile> {
|
||||||
return this.api_base.mediaFile(token)
|
return this.api_base.mediaFile(token)
|
||||||
}
|
}
|
||||||
api_base: StorytellerApiInterface = mockApi ? new StorytellerApiMock() : new StorytellerApiBase();
|
api_base: IStorytellerApi = mockApi ? new StorytellerApiMock() : new StorytellerApiBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ApiError<T extends AxiosResponse = AxiosResponse> extends Error {
|
export class ApiError<T extends AxiosResponse = AxiosResponse> extends Error {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl RemoteAssetReader {
|
|||||||
Ok(reader)
|
Ok(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(all(feature = "wasm", target_family = "wasm"))]
|
||||||
async fn load_local<'a>(&'a self, path: &'a Path) -> Result<Box<Reader<'a>>, AssetReaderError> {
|
async fn load_local<'a>(&'a self, path: &'a Path) -> Result<Box<Reader<'a>>, AssetReaderError> {
|
||||||
let token = path
|
let token = path
|
||||||
.ext_file_prefix()
|
.ext_file_prefix()
|
||||||
@@ -109,12 +109,16 @@ impl AssetReader for RemoteAssetReader {
|
|||||||
&'a self,
|
&'a self,
|
||||||
path: &'a Path,
|
path: &'a Path,
|
||||||
) -> BoxedFuture<'a, Result<Box<Reader<'a>>, AssetReaderError>> {
|
) -> BoxedFuture<'a, Result<Box<Reader<'a>>, AssetReaderError>> {
|
||||||
if cfg!(not(feature = "wasm")) {
|
#[cfg(not(all(feature = "wasm", target_family = "wasm")))]
|
||||||
|
{
|
||||||
info!("wasm mode not detected");
|
info!("wasm mode not detected");
|
||||||
// NB: Headless mode (server rendering) is running without a Tokio runtime.
|
// NB: Headless mode (server rendering) is running without a Tokio runtime.
|
||||||
// The reqwest HTTP client requires async-compat to function at runtime.
|
// The reqwest HTTP client requires async-compat to function at runtime.
|
||||||
Box::pin(Compat::new(async move { self.load(path).await }))
|
Box::pin(Compat::new(async move { self.load(path).await }))
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "wasm", target_family = "wasm"))]
|
||||||
|
{
|
||||||
info!("wasm mode");
|
info!("wasm mode");
|
||||||
if let Some(window) = web_sys::window() {
|
if let Some(window) = web_sys::window() {
|
||||||
if let Ok(search) = window.location().search() {
|
if let Ok(search) = window.location().search() {
|
||||||
@@ -159,7 +163,7 @@ impl IntoError<AssetReaderError> for reqwest::Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(all(feature = "wasm", target_family = "wasm"))]
|
||||||
mod wasm {
|
mod wasm {
|
||||||
use std::task::Waker;
|
use std::task::Waker;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user