-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efd8646
commit 4c403d2
Showing
10 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { SavedLayoutMeta } from "../types/SavedBlocks"; | ||
// Limitation API for getBlocks | ||
export const TOTAL_COUNT = 200; | ||
export const normalBlocks = ( | ||
data: SavedLayoutMeta[], | ||
screenshotUrl: string | ||
) => { | ||
return data | ||
.filter((item) => item.meta.type === "normal") | ||
.map((item) => { | ||
return { | ||
...item, | ||
meta: { | ||
...item.meta, | ||
_thumbnailSrc: `${screenshotUrl}/${item.meta._thumbnailSrc}` | ||
} | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { createBlockScreenshot, updateBlockScreenshot } from "../api"; | ||
import { Screenshots } from "../types/Screenshots"; | ||
import { t } from "../utils/i18n"; | ||
import { getScreenshotUrl } from "./utils"; | ||
|
||
export const screenshots = (): Screenshots => { | ||
return { | ||
getScreenshotUrl, | ||
async create(res, rej, data) { | ||
try { | ||
const r = await createBlockScreenshot(data); | ||
res(r); | ||
} catch (e) { | ||
console.error("API Client Create Screenshots:", e); | ||
rej(t("Failed to create screenshot")); | ||
} | ||
}, | ||
async update(res, rej, data) { | ||
try { | ||
const r = await updateBlockScreenshot(data); | ||
res(r); | ||
} catch (e) { | ||
console.error("API Client Update Screenshots:", e); | ||
rej(t("Failed to update screenshot")); | ||
} | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Config, getConfig } from "../config"; | ||
import { ScreenshotType } from "../types/Screenshots"; | ||
import { MValue } from "../utils/types"; | ||
import { urlContainsQueryString } from "../utils/url/urlContainerQueryString"; | ||
export const getScreenshotUrl = ({ | ||
_thumbnailSrc, | ||
type | ||
}: ScreenshotType): string => { | ||
const config = getConfig(); | ||
const siteUrl = determineScreenshotUrl(type, config); | ||
|
||
return urlContainsQueryString(siteUrl) | ||
? `${siteUrl}&${_thumbnailSrc}` | ||
: `${siteUrl}?${_thumbnailSrc}`; | ||
}; | ||
|
||
const determineScreenshotUrl = ( | ||
type: string, | ||
config: MValue<Config> | ||
): string => { | ||
switch (type) { | ||
case "normal": | ||
return config?.api.screenshots.normalScreenshotUrl ?? ""; | ||
case "global": | ||
return config?.api.screenshots.globalScreenshotUrl ?? ""; | ||
case "saved": | ||
return config?.api.screenshots.savedScreenshotUrl ?? ""; | ||
case "layout": | ||
return config?.api.screenshots.layoutScreenshotUrl ?? ""; | ||
default: | ||
return ""; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Response } from "./Response"; | ||
|
||
export interface ScreenshotData { | ||
base64: string; | ||
blockType: "normal" | "global" | "saved" | "layout"; | ||
} | ||
|
||
export type ScreenshotType = { | ||
_thumbnailSrc: string; | ||
type: string; | ||
}; | ||
|
||
export interface Screenshots { | ||
getScreenshotUrl?: ({ _thumbnailSrc, type }: ScreenshotType) => string; | ||
create?: ( | ||
res: Response<{ id: string }>, | ||
rej: Response<string>, | ||
extra: ScreenshotData | ||
) => void; | ||
update?: ( | ||
res: Response<{ id: string }>, | ||
rej: Response<string>, | ||
extra: ScreenshotData & { id: string } | ||
) => void; | ||
} |
2 changes: 2 additions & 0 deletions
2
public/editor-client/src/utils/url/urlContainerQueryString.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const urlContainsQueryString = (url: string): boolean => | ||
url.includes("?"); |