mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-30 20:21:51 +01:00
fix permission check on domain level
This commit is contained in:
parent
9488437698
commit
fa2b610ea6
@ -10,7 +10,7 @@ let activeExtension = false;
|
|||||||
|
|
||||||
function sendMessage<MessageKey extends keyof MessagesMetadata>(
|
function sendMessage<MessageKey extends keyof MessagesMetadata>(
|
||||||
message: MessageKey,
|
message: MessageKey,
|
||||||
payload: MessagesMetadata[MessageKey]["req"],
|
payload: MessagesMetadata[MessageKey]["req"] | undefined = undefined,
|
||||||
timeout: number = -1,
|
timeout: number = -1,
|
||||||
) {
|
) {
|
||||||
return new Promise<MessagesMetadata[MessageKey]["res"] | null>((resolve) => {
|
return new Promise<MessagesMetadata[MessageKey]["res"] | null>((resolve) => {
|
||||||
@ -54,9 +54,7 @@ export async function sendPage(
|
|||||||
export async function extensionInfo(): Promise<
|
export async function extensionInfo(): Promise<
|
||||||
MessagesMetadata["hello"]["res"] | null
|
MessagesMetadata["hello"]["res"] | null
|
||||||
> {
|
> {
|
||||||
const message = await sendMessage("hello", {}, 300);
|
const message = await sendMessage("hello", undefined, 300);
|
||||||
if (!message?.success) return null;
|
|
||||||
if (!message.allowed) return null;
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,15 +45,17 @@ export function MetaPart(props: MetaPartProps) {
|
|||||||
|
|
||||||
const { error, value, loading } = useAsync(async () => {
|
const { error, value, loading } = useAsync(async () => {
|
||||||
const info = await extensionInfo();
|
const info = await extensionInfo();
|
||||||
const isAllowed = info?.success && isAllowedExtensionVersion(info.version);
|
const isValidExtension =
|
||||||
|
info?.success && isAllowedExtensionVersion(info.version);
|
||||||
|
|
||||||
if (isAllowed) {
|
if (isValidExtension) {
|
||||||
if (!info.hasPermission) throw new Error("extension-no-permission");
|
if (!info.allowed || !info.hasPermission)
|
||||||
|
throw new Error("extension-no-permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
// use api metadata or providers metadata
|
// use api metadata or providers metadata
|
||||||
const providerApiUrl = getLoadbalancedProviderApiUrl();
|
const providerApiUrl = getLoadbalancedProviderApiUrl();
|
||||||
if (providerApiUrl && !isAllowed) {
|
if (providerApiUrl && !isValidExtension) {
|
||||||
try {
|
try {
|
||||||
await fetchMetadata(providerApiUrl);
|
await fetchMetadata(providerApiUrl);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user