Skip to content

Commit

Permalink
fix: host_permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
iszhouhua committed Oct 29, 2024
1 parent 4edadd5 commit a4805c8
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 53 deletions.
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,7 @@ PS:打赏时请备注捐赠者,如有遗漏请联系我添加。

## 交流群

### Telegram交流群

群组链接:[https://t.me/SocialMediaCopilot](https://t.me/SocialMediaCopilot)

### QQ交流群

<img width="400px" src="docs/images/QQ群二维码.png" />

### 微信交流群

<img width="400px" src="docs/images/微信群二维码.png" />

> 如二维码已失效,可加作者微信。记得备注来意
<img width="400px" src="src/assets/images//wechat-qr-code.png" />
[点击查看群组信息](docs/交流群.md)

## 常见问题

Expand Down
Binary file removed docs/images/QQ群二维码.png
Binary file not shown.
File renamed without changes
Binary file added docs/images/wechat-group-qr-code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/微信群二维码.png
Binary file not shown.
17 changes: 17 additions & 0 deletions docs/交流群.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 交流群

## Telegram交流群

群组链接:[https://t.me/SocialMediaCopilot](https://t.me/SocialMediaCopilot)

## QQ交流群

<img width="400px" src="images/qq-group-qr-code.png" />

## 微信交流群

<img width="400px" src="images/wechat-group-qr-code.png" />

> 如二维码已失效,可加作者微信。记得备注来意
<img width="400px" src="../src/assets/images/wechat-qr-code.png" />
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "social-media-copilot",
"private": true,
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"author": "Andy Zhou <[email protected]>",
"engines": {
Expand Down
78 changes: 78 additions & 0 deletions src/components/form-field/material-types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
import { ControllerProps, FieldPath, FieldValues } from "react-hook-form";
import { Checkbox } from "@/components/ui/checkbox";

export const MaterialTypesFormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
>(props: Omit<ControllerProps<TFieldValues, TName>, "render"> & {
items: { value: string, label: string, required?: boolean }[]
}) => {
const { items, ...restProps } = props;
return (
<FormField
{...restProps}
render={({ field }) => {
const [needMaterial, setNeedMaterial] = useState<boolean | 'indeterminate'>(false);
useEffect(() => {
if (!needMaterial) {
field.onChange([]);
return;
}
field.onChange(items.filter((item) => item.required).map((item) => item.value));
}, [needMaterial])

return (
<FormItem>
<div className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4 shadow mb-4">
<Checkbox
checked={needMaterial}
onCheckedChange={setNeedMaterial}
/>
<div className="space-y-1 leading-none">
<FormLabel>同时导出素材</FormLabel>
<FormDescription>
{import.meta.env.EDGE ? "请确认Edge下载设置中的”每次下载都询问我该做些什么“选项处于关闭状态。否则,下载区域会弹出很多“打开”和“另存为”的选项按钮。" : "请确认Chrome下载设置中的”下载前询问每个文件的保存位置“选项未被选中。否则,会弹出很多“另存为”对话框。"}
</FormDescription>
</div>
</div>
{needMaterial && <div className="mr-4 flex items-center space-x-4">
<FormLabel>素材类型</FormLabel>
{items.map((item) => (
<FormField
key={item.value}
{...restProps}
render={() => {
return (
<FormItem
key={field.value}
className="flex items-center space-x-2 space-y-0"
>
<FormControl>
<Checkbox
disabled={item.required}
checked={field.value?.includes(item.value)}
onCheckedChange={(checked) => {
return checked
? field.onChange([...field.value, item.value])
: field.onChange(
field.value?.filter(
(value: string) => value !== item.value
)
)
}}
/>
</FormControl>
<FormLabel className="text-sm font-normal">{item.label}</FormLabel>
</FormItem>
)
}}
/>
))}
</div>}
<FormMessage />
</FormItem>
)
}}
/>)
}
4 changes: 2 additions & 2 deletions src/components/popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Contact, JapaneseYen, MessageCircleWarning, MessageSquare, MessageSquar
import { CollapsibleItem, Item } from "./item";
import { UnsupportedPlatform } from "./unsupported";
import wechatQrCode from "@/assets/images/wechat-qr-code.png";
import qqGroupQrCode from "@/assets/images/qq-group-qr-code.png";
import appreciationCode from "@/assets/images/appreciation-code.png";
import type { Platform } from "@/platforms";

Expand Down Expand Up @@ -42,7 +41,8 @@ export const Popup = () => {
<CollapsibleItem icon={Contact} title="沟通交流">
<Item icon={MessageCircleWarning} title="功能反馈" onClick={() => window.open('https://github.com/iszhouhua/social-media-copilot/issues')} />
<Item icon={MessageSquareText} title="Telegram交流群" onClick={() => window.open('https://t.me/SocialMediaCopilot')} />
<Item icon={MessageSquareText} title="QQ交流群" onClick={() => window.open(qqGroupQrCode)} />
<Item icon={MessageSquareText} title="QQ交流群" onClick={() => window.open('https://gitee.com/iszhouhua/social-media-copilot/raw/main/docs/images/qq-group-qr-code.png')} />
<Item icon={MessageSquare} title="微信交流群" onClick={() => window.open('https://gitee.com/iszhouhua/social-media-copilot/raw/main/docs/images/wechat-group-qr-code.png')} />
<Item icon={MessageSquare} title="添加微信" onClick={() => window.open(wechatQrCode)} />
</CollapsibleItem>
<Item icon={JapaneseYen} title="打赏作者" onClick={() => window.open(appreciationCode)} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/task/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const TaskDialog = React.forwardRef<{ start: StartFunc; }, { children: Re
} else {
url = file.data;
}
await browser.runtime.sendMessage<"download">({ name: "download", body: { url, filename: file.filename } });
await browser.runtime.sendMessage<"download">({ name: "download", body: { url, filename: file.filename, path: file.path } });
URL.revokeObjectURL(url);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/task/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type TaskSetStateActions = {
setStatus: React.Dispatch<React.SetStateAction<TaskStatus>>;
}

export type TaskFileInfo = { filename: string } & (
export type TaskFileInfo = { filename: string, path?: string } & (
| {
type: 'blob';
data: Blob;
Expand Down Expand Up @@ -62,7 +62,7 @@ export abstract class TaskProcessor<P = any, T = any> {
}
await delay(1000);
const res = await func(...args);
if(!res){
if (!res) {
throw new Error("接口返回内容为空,可能已触发平台风控");
}
requestCache.set(key, res);
Expand All @@ -78,7 +78,7 @@ export abstract class TaskProcessor<P = any, T = any> {
return {
data: new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }),
type: 'blob',
filename: `${name}-${moment().format("YYYYMMDD-HHmmss")}.xlsx`,
filename: `社媒助手-${name}-${moment().format("YYYYMMDD-HHmmss")}.xlsx`,
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/entrypoints/background/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export default async function handleMessage(
if (body.filename) {
// 替换掉特殊字符
body.filename = "【社媒助手】" + body.filename.replace(/[^\w\u4e00-\u9fa5\.\-\_]/g, "");
if (body.path) {
body.filename = `${body.path}/${body.filename}`;
}
}
delete body.path;
return browser.downloads.download(body);
}
}
Expand All @@ -35,20 +39,10 @@ async function executeScript(code: string, sender: Runtime.MessageSender) {
return injectionResults?.[0]?.result;
}
async function getRealUrl(url: string) {
const origins = [url];
if (new URL(url).hostname === "v.douyin.com") {
origins.push('*://www.iesdouyin.com/*');
}
const granted = await browser.permissions.request({ origins });
if (!granted) return;
const response = await fetch(url);
return response.url;
}

async function executionFetch(body: Array<any>) {
const granted = await browser.permissions.request({
origins: [body[0]]
});
if (!granted) return;
return fetch(body[0], body?.[1]).then(res => res.json());
}
10 changes: 10 additions & 0 deletions src/platforms/dy/http/aweme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ export interface AwemeDetail {
// 2:图文 4:视频
media_type: number;
video: VideoInfo;
music: any;
images: ImageInfo[];
statistics: Statistics;
author: AuthorInfo;
}

export interface VideoInfo {
duration: number;
format: string;
origin_cover: {
uri: string;
height: number;
width: number;
};
cover: {
uri: string;
url_key: string;
height: number;
width: number;
data_size: number;
url_list: string[];
};
play_addr: {
uri: string;
url_key: string;
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/dy/injects/video-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Component = (props: {
const zip = new JSZip();
aweme.images?.map((item) => item.url_list.reverse()[0]).forEach((image, index) => {
const imageData = fetch(image).then((res) => res.blob());
zip.file(`图${index + 1}.png`, imageData, { binary: true });
zip.file(`图${index + 1}.jpeg`, imageData, { binary: true });
});
const blob = await zip.generateAsync({ type: "blob" });
url = URL.createObjectURL(blob);
Expand Down
14 changes: 9 additions & 5 deletions src/platforms/dy/tasks/author-post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { throttle } from "lodash";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { NeedMediaFormField } from "@/components/form-field/need-media";
import { TaskDialog } from "@/components/task";
import { Processor } from "./processor";
import { LimitPerIdFormField } from "@/components/form-field/limit-per-id";
import { parseAuthorId } from "../author";
import { TextareaArrayFormField,textareaArrayTransform } from "@/components/form-field/textarea-array";
import { TextareaArrayFormField, textareaArrayTransform } from "@/components/form-field/textarea-array";
import { MaterialTypesFormField } from "@/components/form-field/material-types";

const formSchema = z.object({
needMedia: z.boolean().default(false).optional(),
limitPerId: z.coerce.number().min(1, "请输入需要导出的数量"),
authorIds: z.string().array().or(z.string().trim().min(1, "需要导出的数据不能为空").transform((arg, ctx) => textareaArrayTransform(arg, ctx, parseAuthorId))),
materialTypes: z.string().array()
});

export type FormSchema = z.infer<typeof formSchema>;
Expand All @@ -37,9 +37,9 @@ export default (props: {
const form = useForm<FormSchema>({
resolver: zodResolver(formSchema),
defaultValues: {
needMedia: false,
authorIds: author ? [author.authorId] : [],
limitPerId: author?.postCount || parseInt(localStorage.getItem(storageKey) ?? "10"),
materialTypes: []
}
});

Expand All @@ -66,7 +66,11 @@ export default (props: {
control={form.control}
name="limitPerId"
description={author ? `当前达人共有${author.postCount}个作品` : '每位达人需要导出的视频数量'} />
<NeedMediaFormField control={form.control} name="needMedia" />
<MaterialTypesFormField control={form.control} name="materialTypes" items={[
{ label: "视频/图集", value: "video", required: true },
{ label: "封面", value: "cover" },
{ label: "音乐", value: "music" },
]} />
</form>
</Form>
<DialogFooter>
Expand Down
Loading

0 comments on commit a4805c8

Please sign in to comment.