feat(workflow): add record when upload file (#1975)

This commit is contained in:
July
2025-09-02 20:56:01 +08:00
committed by zhuangjie.1125
parent 2635f06afb
commit 4987e3d8d5
9 changed files with 1335 additions and 4 deletions

View File

@ -22340,6 +22340,9 @@ importers:
'@coze-project-ide/framework':
specifier: workspace:*
version: link:../../project-ide/framework
'@coze-studio/api-schema':
specifier: workspace:*
version: link:../../arch/api-schema
'@coze-studio/bot-detail-store':
specifier: workspace:*
version: link:../../studio/stores/bot-detail

View File

@ -24,6 +24,7 @@ const config = [
entries: {
passport: './idl/passport/passport.thrift', // Entry service name and path
explore: './idl/marketplace/public_api.thrift',
upload: './idl/upload/upload.thrift',
},
commonCodePath: path.resolve(__dirname, './src/api/config.ts'), // custom profile
output: './src', // Product location

View File

@ -8,7 +8,8 @@
"exports": {
".": "./src/index.ts",
"./passport": "./src/idl/passport/passport.ts",
"./marketplace": "./src/idl/marketplace/public_api.ts"
"./marketplace": "./src/idl/marketplace/public_api.ts",
"./upload": "./src/idl/upload/upload.ts"
},
"main": "src/index.ts",
"typesVersions": {
@ -18,6 +19,9 @@
],
"marketplace": [
"./src/idl/marketplace/public_api.ts"
],
"upload": [
"./src/idl/upload/upload.ts"
]
}
},

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,157 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as bot_common from './../app/bot_common';
export { bot_common };
import * as base from './../base';
export { base };
import { createAPI } from './../../api/config';
export interface CommonUploadRequest {
ByteData?: Blob,
uploadID?: string,
partNumber?: string,
}
export interface Error {
code: number,
error: string,
error_code: number,
message: string,
}
export interface Payload {
hash: string,
key: string,
uploadID: string,
}
export interface CommonUploadResponse {
Version: string,
success: number,
error: Error,
payload: Payload,
}
export interface ApplyUploadActionRequest {
Action?: string,
Version?: string,
ServiceId?: string,
FileExtension?: string,
FileSize?: string,
s?: string,
ByteData?: Blob,
}
export interface ResponseMetadata {
RequestId: string,
Action: string,
Version: string,
Service: string,
Region: string,
}
export interface StoreInfo {
StoreUri: string,
Auth: string,
UploadID: string,
}
export interface UploadAddress {
StoreInfos: StoreInfo[],
UploadHosts: string[],
UploadHeader?: {
[key: string | number]: string
},
SessionKey: string,
Cloud: string,
}
export interface UploadNode {
StoreInfos: StoreInfo[],
UploadHost: string,
UploadHeader?: {
[key: string | number]: string
},
SessionKey: string,
}
export interface InnerUploadAddress {
UploadNodes: UploadNode[]
}
export interface UploadResult {
Uri: string,
UriStatus: number,
}
export interface PluginResult {
FileName: string,
SourceUri: string,
ImageUri: string,
ImageWidth: number,
ImageHeight: number,
ImageMd5: string,
ImageFormat: string,
ImageSize: number,
FrameCnt: number,
}
export interface ApplyUploadActionResult {
UploadAddress?: UploadAddress,
FallbackUploadAddress?: UploadAddress,
InnerUploadAddress?: InnerUploadAddress,
RequestId?: string,
SDKParam?: string,
Results?: UploadResult[],
PluginResult?: PluginResult[],
}
export interface ApplyUploadActionResponse {
ResponseMetadata: ResponseMetadata,
Result: ApplyUploadActionResult,
}
export interface RecordFileInfoRequest {
FileURI: string,
FileName: string,
FileSize?: string,
FileExtension?: string,
}
export interface RecordFileInfoResponse {}
export const CommonUpload = /*#__PURE__*/createAPI<CommonUploadRequest, CommonUploadResponse>({
"url": "/api/common/upload/*tos_uri",
"method": "POST",
"name": "CommonUpload",
"reqType": "CommonUploadRequest",
"reqMapping": {
"raw_body": [],
"query": ["uploadID", "partNumber"]
},
"resType": "CommonUploadResponse",
"schemaRoot": "api://schemas/idl_upload_upload",
"service": "upload"
});
export const ApplyUploadAction = /*#__PURE__*/createAPI<ApplyUploadActionRequest, ApplyUploadActionResponse>({
"url": "/api/common/upload/apply_upload_action",
"method": "POST",
"name": "ApplyUploadAction",
"reqType": "ApplyUploadActionRequest",
"reqMapping": {
"query": ["Action", "Version", "ServiceId", "FileExtension", "FileSize", "s"],
"raw_body": []
},
"resType": "ApplyUploadActionResponse",
"schemaRoot": "api://schemas/idl_upload_upload",
"service": "upload"
});
export const RecordFileInfo = /*#__PURE__*/createAPI<RecordFileInfoRequest, RecordFileInfoResponse>({
"url": "/api/common/record_file_info",
"method": "POST",
"name": "RecordFileInfo",
"reqType": "RecordFileInfoRequest",
"reqMapping": {
"body": ["FileURI", "FileName", "FileSize", "FileExtension"]
},
"resType": "RecordFileInfoResponse",
"schemaRoot": "api://schemas/idl_upload_upload",
"service": "upload"
});

View File

@ -16,3 +16,4 @@
export * as passport from './idl/passport/passport';
export * as explore from './idl/marketplace/public_api';
export * as upload from './idl/upload/upload';

View File

@ -92,6 +92,7 @@
"@coze-foundation/layout": "workspace:*",
"@coze-foundation/local-storage": "workspace:*",
"@coze-project-ide/framework": "workspace:*",
"@coze-studio/api-schema": "workspace:*",
"@coze-studio/bot-detail-store": "workspace:*",
"@coze-studio/components": "workspace:*",
"@coze-studio/open-chat": "workspace:*",

View File

@ -20,10 +20,11 @@ import { useState } from 'react';
import { nanoid } from 'nanoid';
import { workflowApi } from '@coze-workflow/base/api';
import { type ViewVariableType } from '@coze-workflow/base';
import { upload as uploadAPI } from '@coze-studio/api-schema';
import { I18n } from '@coze-arch/i18n';
import { Toast } from '@coze-arch/coze-design';
import { upLoadFile } from '@coze-arch/bot-utils';
import { CustomError } from '@coze-arch/bot-error';
import { Toast } from '@coze-arch/coze-design';
import { validate } from './validate';
import { FileItemStatus, type FileItem } from './types';
@ -101,7 +102,10 @@ export const useUpload = (props?: UploadConfig) => {
// Upload complete, clear timeout timer
clearTimeout(progressTimer);
await uploadAPI.RecordFileInfo({
FileURI: uri,
FileName: file.name,
});
// Add uri and get the url.
const { url } = await workflowApi.SignImageURL(
{
@ -134,7 +138,8 @@ export const useUpload = (props?: UploadConfig) => {
const validateFile = async (file: FileItem): Promise<string | undefined> => {
const validateMsg = await validate(file, {
customValidate,
maxSize: maxSize ?? fileType === 'image' ? MAX_IMAGE_SIZE : MAX_FILE_SIZE,
maxSize:
(maxSize ?? fileType === 'image') ? MAX_IMAGE_SIZE : MAX_FILE_SIZE,
accept,
});
if (validateMsg) {

View File

@ -53,6 +53,9 @@
{
"path": "../../agent-ide/space-bot/tsconfig.build.json"
},
{
"path": "../../arch/api-schema/tsconfig.build.json"
},
{
"path": "../../arch/bot-api/tsconfig.build.json"
},