mirror of
https://github.com/movie-web/extension.git
synced 2025-09-13 02:53:24 +00:00
Enable TS strict mode and fix all associated errors
This commit is contained in:
@@ -14,6 +14,8 @@ type Response = BaseResponse<{
|
||||
|
||||
const handler: PlasmoMessaging.MessageHandler<BaseRequest, Response> = async (req, res) => {
|
||||
try {
|
||||
if (!req.sender?.tab?.url) throw new Error('No tab URL found in the request.');
|
||||
|
||||
const version = getVersion();
|
||||
res.send({
|
||||
success: true,
|
||||
@@ -21,7 +23,7 @@ const handler: PlasmoMessaging.MessageHandler<BaseRequest, Response> = async (re
|
||||
allowed: await isDomainWhitelisted(req.sender.tab.url),
|
||||
hasPermission: await hasPermission(),
|
||||
});
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
res.send({
|
||||
success: false,
|
||||
error: err.message,
|
||||
|
@@ -32,7 +32,7 @@ type Response<T> = BaseResponse<{
|
||||
const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType']): BodyInit => {
|
||||
if (bodyType === 'FormData') {
|
||||
const formData = new FormData();
|
||||
body.forEach(([key, value]) => {
|
||||
body.forEach(([key, value]: [any, any]) => {
|
||||
formData.append(key, value.toString());
|
||||
});
|
||||
}
|
||||
@@ -50,6 +50,9 @@ const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType']
|
||||
|
||||
const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (req, res) => {
|
||||
try {
|
||||
if (!req.sender?.tab?.url) throw new Error('No tab URL found in the request.');
|
||||
if (!req.body) throw new Error('No request body found in the request.');
|
||||
|
||||
const url = makeFullUrl(req.body.url, req.body);
|
||||
await assertDomainWhitelist(req.sender.tab.url);
|
||||
|
||||
@@ -87,7 +90,7 @@ const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (r
|
||||
finalUrl: response.url,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
console.error('failed request', err);
|
||||
res.send({
|
||||
success: false,
|
||||
|
@@ -11,6 +11,9 @@ type Request = BaseRequest & {
|
||||
|
||||
const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (req, res) => {
|
||||
try {
|
||||
if (!req.sender?.tab?.id) throw new Error('No tab ID found in the request.');
|
||||
if (!req.body) throw new Error('No body found in the request.');
|
||||
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set('redirectUrl', req.body.redirectUrl);
|
||||
const url = (chrome || browser).runtime.getURL(`/tabs/${req.body.page}.html?${searchParams.toString()}`);
|
||||
@@ -26,7 +29,7 @@ const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (re
|
||||
res.send({
|
||||
success: true,
|
||||
});
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
res.send({
|
||||
success: false,
|
||||
error: err.message,
|
||||
|
@@ -15,12 +15,15 @@ interface Request extends BaseRequest {
|
||||
|
||||
const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (req, res) => {
|
||||
try {
|
||||
if (!req.sender?.tab?.url) throw new Error('No tab URL found in the request.');
|
||||
if (!req.body) throw new Error('No request body found in the request.');
|
||||
|
||||
await assertDomainWhitelist(req.sender.tab.url);
|
||||
await setDynamicRules(req.body);
|
||||
res.send({
|
||||
success: true,
|
||||
});
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
res.send({
|
||||
success: false,
|
||||
error: err.message,
|
||||
|
@@ -15,5 +15,5 @@ export function useDomain(): null | string {
|
||||
};
|
||||
}, []);
|
||||
|
||||
return makeUrlIntoDomain(domain);
|
||||
return domain ? makeUrlIntoDomain(domain) : null;
|
||||
}
|
||||
|
@@ -8,12 +8,12 @@ export function useDomainWhitelist() {
|
||||
|
||||
const removeDomain = useCallback((domain: string | null) => {
|
||||
if (!domain) return;
|
||||
setDomainWhitelist((s) => [...s.filter((v) => v !== domain)]);
|
||||
setDomainWhitelist((s) => [...(s ?? []).filter((v) => v !== domain)]);
|
||||
}, []);
|
||||
|
||||
const addDomain = useCallback((domain: string | null) => {
|
||||
if (!domain) return;
|
||||
setDomainWhitelist((s) => [...s.filter((v) => v !== domain), domain]);
|
||||
setDomainWhitelist((s) => [...(s ?? []).filter((v) => v !== domain), domain]);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
|
@@ -123,5 +123,6 @@ export const removeDynamicRules = async (ruleIds: number[]) => {
|
||||
await (chrome || browser).declarativeNetRequest.updateDynamicRules({
|
||||
removeRuleIds: ruleIds,
|
||||
});
|
||||
if ((chrome || browser).runtime.lastError?.message) throw new Error((chrome || browser).runtime.lastError.message);
|
||||
if ((chrome || browser).runtime.lastError?.message)
|
||||
throw new Error((chrome || browser).runtime.lastError?.message ?? 'Unknown error');
|
||||
};
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { isChrome } from './extension';
|
||||
|
||||
export function queryCurrentDomain(cb: (domain: string | null) => void) {
|
||||
const handle = (tabUrl: string | null) => {
|
||||
const handle = (tabUrl: string | undefined) => {
|
||||
if (!tabUrl) cb(null);
|
||||
else cb(tabUrl);
|
||||
};
|
||||
|
@@ -1,18 +1,13 @@
|
||||
{
|
||||
"extends": "plasmo/templates/tsconfig.base",
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"include": [
|
||||
".plasmo/index.d.ts",
|
||||
"./**/*.ts",
|
||||
"./**/*.tsx"
|
||||
],
|
||||
"exclude": ["node_modules"],
|
||||
"include": [".plasmo/index.d.ts", "./**/*.ts", "./**/*.tsx"],
|
||||
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"paths": {
|
||||
"~*": [
|
||||
"./src/*"
|
||||
]
|
||||
"~*": ["./src/*"]
|
||||
},
|
||||
"baseUrl": "."
|
||||
}
|
||||
|
Reference in New Issue
Block a user