mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-14 23:53: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");
|
||||
|
||||
interface StorytellerApiInterface {
|
||||
interface IStorytellerApi {
|
||||
createScene(file: File): Promise<MediaFileToken>
|
||||
session(): Promise<Session>
|
||||
listMediaFiles(options: ListMediaFilesOptions): Promise<ListMediaFilesResult>
|
||||
@@ -18,7 +18,7 @@ interface StorytellerApiInterface {
|
||||
mediaFile(token: MediaFileToken): Promise<MediaFile>
|
||||
}
|
||||
|
||||
class StorytellerApiBase implements StorytellerApiInterface {
|
||||
class StorytellerApiBase implements IStorytellerApi {
|
||||
#api = axios.create({
|
||||
baseURL: "https://api.fakeyou.com",
|
||||
withCredentials: true,
|
||||
@@ -137,7 +137,7 @@ interface LocalDbSchema extends DBSchema {
|
||||
}
|
||||
}
|
||||
|
||||
class StorytellerApiMock implements StorytellerApiInterface {
|
||||
class StorytellerApiMock implements IStorytellerApi {
|
||||
database?: IDBPDatabase<LocalDbSchema>;
|
||||
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> {
|
||||
return this.api_base.createScene(file)
|
||||
}
|
||||
@@ -457,7 +457,7 @@ export class StorytellerApi implements StorytellerApiInterface {
|
||||
mediaFile(token: string): Promise<MediaFile> {
|
||||
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 {
|
||||
|
||||
@@ -80,7 +80,7 @@ impl RemoteAssetReader {
|
||||
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> {
|
||||
let token = path
|
||||
.ext_file_prefix()
|
||||
@@ -109,12 +109,16 @@ impl AssetReader for RemoteAssetReader {
|
||||
&'a self,
|
||||
path: &'a Path,
|
||||
) -> 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");
|
||||
// NB: Headless mode (server rendering) is running without a Tokio runtime.
|
||||
// The reqwest HTTP client requires async-compat to function at runtime.
|
||||
Box::pin(Compat::new(async move { self.load(path).await }))
|
||||
} else {
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "wasm", target_family = "wasm"))]
|
||||
{
|
||||
info!("wasm mode");
|
||||
if let Some(window) = web_sys::window() {
|
||||
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 {
|
||||
use std::task::Waker;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user