Skip to content

Let's use AI to Earn!

bili

daoyianafecf8ff7a06
diff --git a/.env.development b/.env.development
index bad81f21..a240adeb 100644
--- a/.env.development
+++ b/.env.development
@@ -1,5 +1,5 @@
NEXT_PUBLIC_EVN=dev
-# NEXT_PUBLIC_API_URL=http://localhost:7000/api/
+NEXT_PUBLIC_API_URL=http://localhost:7000/api/
-NEXT_PUBLIC_API_URL=https://apitest.aiearn.ai/api/
\ No newline at end of file
+# NEXT_PUBLIC_API_URL=https://apitest.aiearn.ai/api/
\ No newline at end of file
diff --git a/src/api/bilibili.ts b/src/api/bilibili.ts
index 21b862dd..d08a8ea2 100644
--- a/src/api/bilibili.ts
+++ b/src/api/bilibili.ts
@@ -1,5 +1,6 @@
// 创建或更新账户
import sxRequest from "@/utils/request";
+import { request } from '@/utils/request';
/**
* 获取B站登录地址
@@ -20,4 +21,54 @@ export const apiCheckBilibiliAuth = (taskId: string) => {
return sxRequest.post<{ code: number; data: any }>(
`plat/bilibili/auth/create-account/${taskId}`,
);
+};
+
+/**
+ * 初始化视频
+ * @param accountId 账户ID
+ * @returns
+ */
+export const apiInitBilibiliVideo = (accountId: string) => {
+ return sxRequest.post<{ code: number; data: any }>(
+ `plat/bilibili/video/init`,
+ );
+};
+
+/**
+ * 上传B站视频封面
+ * @param accountId 账户ID
+ * @param file 封面文件
+ * @returns
+ */
+export const apiUploadBilibiliCover = (accountId: string, data: any) => {
+ return request({
+ url: 'plat/bilibili/cover/upload',
+ method: 'POST',
+ body: data,
+ });
+};
+
+/**
+ * 提交B站稿件
+ * @param accountId 账户ID
+ * @param data 稿件数据
+ * @returns
+ */
+export const apiSubmitBilibiliArchive = (
+ accountId: string,
+ data: {
+ title: string;
+ cover: string;
+ tid: number;
+ noReprint: number;
+ desc: string;
+ tag: string[];
+ copyright: number;
+ source: string;
+ },
+) => {
+ return sxRequest.post<{ code: number; data: any }>(
+ `plat/bilibili/archive/add-by-utoken/${accountId}`,
+ data,
+ );
};
diff --git a/src/app/[lng]/accounts/plat/BilibiliLogin.ts b/src/app/[lng]/accounts/plat/BilibiliLogin.ts
index d2f13cf9..c4ced28d 100644
--- a/src/app/[lng]/accounts/plat/BilibiliLogin.ts
+++ b/src/app/[lng]/accounts/plat/BilibiliLogin.ts
@@ -4,7 +4,7 @@ import { requestPlatApi } from "@/utils/otherRequest";
import { KwaiPlat } from "@/app/plat/platChildren/kwai/KwaiPlat";
import { createOrUpdateAccountApi } from "@/api/account";
import { apiGetBilibiliLoginUrl, apiCheckBilibiliAuth } from "@/api/bilibili";
-import { message } from "antd";
+import { useAccountStore } from "@/store/account";
export const kwaiAppId = "ks715790869885446758";
export const kwaiAppSecret = "cqSvJvBSPJjd-4pBH_4N0Q";
@@ -42,13 +42,17 @@ export function bilibiliLogin(taskId:any): Promise<any> {
// 开始轮询检查授权状态
const checkAuthStatus = async () => {
try {
- const authRes = await apiCheckBilibiliAuth(taskId);
- // if (authRes?.code === 0 && authRes?.data) {
- // message.success('授权成功');
- // resolve(authRes.data);
- // return true;
- // }
- return false;
+ const authRess:any = await apiCheckBilibiliAuth(taskId);
+ let authRes = authRess.data;
+ if (authRes?.code === 0 && authRes?.data.status == 1) {
+ // message.success('授权成功');
+ // useAccountStore
+ const accountStore = useAccountStore.getState();
+ await accountStore.getAccountList();
+ resolve(authRes);
+ return true;
+ }
+ // return false;
} catch (error) {
console.error('检查授权状态失败:', error);
return false;
@@ -66,7 +70,7 @@ export function bilibiliLogin(taskId:any): Promise<any> {
// 5分钟后自动停止轮询
setTimeout(() => {
clearInterval(interval);
- message.error('授权超时,请重试');
+ // message.error('授权超时,请重试');
reject(new Error('授权超时'));
}, 5 * 60 * 1000);
diff --git a/src/app/[lng]/demo/demoPageCore.tsx b/src/app/[lng]/demo/demoPageCore.tsx
index 25a34aae..d00c5cc9 100644
--- a/src/app/[lng]/demo/demoPageCore.tsx
+++ b/src/app/[lng]/demo/demoPageCore.tsx
@@ -1,8 +1,185 @@
"use client";
import { useTransClient } from "@/app/i18n/client";
+import { useAccountStore } from "@/store/account";
+import { useEffect, useState } from "react";
+import { apiInitBilibiliVideo, apiUploadBilibiliCover, apiSubmitBilibiliArchive } from "@/api/bilibili";
+import { getAccountListApi } from "@/api/account";
+
+interface Account {
+ id: string;
+ type: string;
+ nickname: string;
+ avatar: string;
+}
export const DemoPageCore = () => {
const { t } = useTransClient("demo");
- return <div>{t("demoText")}</div>;
+ const accountStore = useAccountStore();
+ const [accounts, setAccounts] = useState<Account[]>([]);
+ const [uploadToken, setUploadToken] = useState<string>("");
+ const [selectedFile, setSelectedFile] = useState<File | null>(null);
+ const [coverFile, setCoverFile] = useState<File | null>(null);
+ const [uploadProgress, setUploadProgress] = useState<number>(0);
+
+ useEffect(() => {
+ const fetchAccounts = async () => {
+ const result = await getAccountListApi();
+ console.log('accountList', result);
+ if (result?.code === 0 && result?.data) {
+ setAccounts(result.data);
+ }
+ };
+ fetchAccounts();
+ }, []);
+
+ const handleInitVideo = async (accountId: string) => {
+ try {
+ const res:any = await apiInitBilibiliVideo(accountId);
+ if (res?.data?.upload_token) {
+ setUploadToken(res.data.upload_token);
+ console.log('获取上传token成功:', res.data.upload_token);
+ }
+ } catch (error) {
+ console.error('获取上传token失败:', error);
+ }
+ };
+
+ const handleVideoUpload = async (file: File) => {
+ if (!uploadToken) {
+ console.error('请先获取上传token');
+ return;
+ }
+
+ try {
+ const response = await fetch(
+ `https://openupos.bilivideo.com/video/v2/upload?upload_token=${uploadToken}`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: file,
+ }
+ );
+
+ if (response.ok) {
+ const result = await response.json();
+ console.log('视频上传成功:', result);
+ return true;
+ } else {
+ throw new Error('视频上传失败');
+ }
+ } catch (error) {
+ console.error('视频上传失败:', error);
+ return false;
+ }
+ };
+
+ const handleUploadCover = async (accountId: string) => {
+ if (!coverFile) {
+ console.error('请选择封面文件');
+ return null;
+ }
+
+ try {
+ const formData = new FormData();
+ formData.append('file', coverFile);
+ const res:any = await apiUploadBilibiliCover(accountId, formData);
+ if (res?.data?.url) {
+ console.log('封面上传成功:', res.data.url);
+ return res.data.url;
+ }
+ return null;
+ } catch (error) {
+ console.error('封面上传失败:', error);
+ return null;
+ }
+ };
+
+ const handleSubmitArchive = async (accountId: string) => {
+ try {
+ const coverUrl = await handleUploadCover(accountId);
+ if (!coverUrl) {
+ console.error('封面上传失败,无法提交稿件');
+ return;
+ }
+
+ const archiveData = {
+ title: "测试视频标题",
+ cover: coverUrl,
+ tid: 1,
+ noReprint: 0,
+ desc: "测试视频描述",
+ tag: ["测试", "视频"],
+ copyright: 0,
+ source: "测试来源"
+ };
+
+ const res = await apiSubmitBilibiliArchive(accountId, archiveData);
+ console.log('稿件提交结果:', res);
+ } catch (error) {
+ console.error('稿件提交失败:', error);
+ }
+ };
+
+ const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>, type: 'video' | 'cover') => {
+ const file = event.target.files?.[0];
+ if (file) {
+ if (type === 'video') {
+ setSelectedFile(file);
+ } else {
+ setCoverFile(file);
+ }
+ }
+ };
+
+ return (
+ <div>
+ <div>{t("demoText")}</div>
+ <div>
+ <h3>账户列表:</h3>
+ {accounts.map((account) => (
+ <div key={account.id}>
+ <p>平台: {account.type}</p>
+ <p>昵称: {account.nickname}</p>
+ <p>头像: <img src={account.avatar} alt="avatar" width={50} height={50} /></p>
+ <button onClick={() => handleInitVideo(account.id)}>获取上传Token</button>
+
+ <div style={{ marginTop: '10px' }}>
+ <input
+ type="file"
+ accept="video/*"
+ onChange={(e) => handleFileChange(e, 'video')}
+ />
+ {selectedFile && (
+ <button onClick={() => handleVideoUpload(selectedFile)}>
+ 上传视频
+ </button>
+ )}
+ </div>
+
+ <div style={{ marginTop: '10px' }}>
+ <input
+ type="file"
+ accept="image/*"
+ onChange={(e) => handleFileChange(e, 'cover')}
+ />
+ {coverFile && (
+ <button onClick={() => handleUploadCover(account.id)}>
+ 上传封面
+ </button>
+ )}
+ </div>
+
+ <div style={{ marginTop: '10px' }}>
+ <button onClick={() => handleSubmitArchive(account.id)}>
+ 提交稿件
+ </button>
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ );
};