Compare commits
No commits in common. "db6c19dae12671984807f9c401ef90b1b952bc3a" and "d55730f317a083a6b6bd06367feb8f46a050a65c" have entirely different histories.
db6c19dae1
...
d55730f317
|
|
@ -76,8 +76,8 @@ export class BowongAISDK {
|
|||
* @private
|
||||
*/
|
||||
private async _uploadFileForH5(params: UploadParams): Promise<string> {
|
||||
const { filePath, name, type } = params;
|
||||
const url = `${this.baseUrl}/api/file/upload/s3`;
|
||||
const { filePath, name, type, onProgress } = params;
|
||||
const url = `${this._isH5Platform() ? '' : this.baseUrl}/api/file/upload/s3`;
|
||||
|
||||
try {
|
||||
// 获取文件信息
|
||||
|
|
@ -94,7 +94,7 @@ export class BowongAISDK {
|
|||
}
|
||||
|
||||
// 自动生成文件名(如果未提供)
|
||||
const fileName = this._generateFileName(filePath, name, type);
|
||||
const fileName = name || `upload_${Date.now()}.${this._getFileExtension(filePath)}`;
|
||||
// 自动判断文件类型(如果未提供)
|
||||
const fileType = type || this._getMimeType(filePath);
|
||||
|
||||
|
|
@ -106,12 +106,12 @@ export class BowongAISDK {
|
|||
|
||||
// 创建FormData
|
||||
const formData = new FormData();
|
||||
|
||||
|
||||
// 在H5环境中,需要先将filePath转换为File对象
|
||||
const response = await fetch(filePath);
|
||||
const blob = await response.blob();
|
||||
const file = new File([blob], fileName, { type: fileType });
|
||||
|
||||
|
||||
formData.append('file', file);
|
||||
formData.append('filename', fileName);
|
||||
formData.append('type', fileType);
|
||||
|
|
@ -164,13 +164,13 @@ export class BowongAISDK {
|
|||
if (img_file) {
|
||||
// 创建FormData
|
||||
const formData = new FormData();
|
||||
|
||||
|
||||
// 在H5环境中,需要先将filePath转换为File对象
|
||||
const response = await fetch(img_file);
|
||||
const blob = await response.blob();
|
||||
const fileName = `generate_${Date.now()}.${this._getFileExtension(img_file)}`;
|
||||
const file = new File([blob], fileName, { type: this._getMimeType(img_file) });
|
||||
|
||||
|
||||
formData.append('img_file', file);
|
||||
formData.append('prompt', prompt);
|
||||
formData.append('model_name', model_name);
|
||||
|
|
@ -238,7 +238,7 @@ export class BowongAISDK {
|
|||
fileInfo = { size: 0 };
|
||||
}
|
||||
// 自动生成文件名(如果未提供)
|
||||
const fileName = this._generateFileName(filePath, name, type);
|
||||
const fileName = name || `upload_${Date.now()}.${this._getFileExtension(filePath)}`;
|
||||
|
||||
// 自动判断文件类型(如果未提供)
|
||||
const fileType = type || this._getMimeType(filePath);
|
||||
|
|
@ -349,12 +349,10 @@ export class BowongAISDK {
|
|||
|
||||
// 上传第一张图片
|
||||
const filePath = chooseResult.tempFilePaths[0];
|
||||
const tempFile = chooseResult.tempFiles[0]
|
||||
console.log('开始上传图片:', filePath);
|
||||
|
||||
const uploadUrl = await this.upload({
|
||||
filePath,
|
||||
type: tempFile.type,
|
||||
onProgress
|
||||
});
|
||||
|
||||
|
|
@ -363,14 +361,14 @@ export class BowongAISDK {
|
|||
|
||||
} catch (error) {
|
||||
console.error('选择并上传图片失败:', error);
|
||||
|
||||
|
||||
// 检查是否是授权被拒绝的错误
|
||||
if (this._isAuthorizationError(error)) {
|
||||
await this._handleAuthorizationError();
|
||||
// 用户重新授权后,递归调用自己重试
|
||||
return this.chooseAndUploadImage(options);
|
||||
}
|
||||
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -383,13 +381,13 @@ export class BowongAISDK {
|
|||
if (!error || typeof error.errMsg !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const errMsg = error.errMsg.toLowerCase();
|
||||
return errMsg.includes('auth') ||
|
||||
errMsg.includes('permission') ||
|
||||
errMsg.includes('denied') ||
|
||||
errMsg.includes('authorize') ||
|
||||
errMsg.includes('scope');
|
||||
return errMsg.includes('auth') ||
|
||||
errMsg.includes('permission') ||
|
||||
errMsg.includes('denied') ||
|
||||
errMsg.includes('authorize') ||
|
||||
errMsg.includes('scope');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -411,9 +409,9 @@ export class BowongAISDK {
|
|||
success: (settingResult) => {
|
||||
console.log('用户设置结果:', settingResult);
|
||||
// 检查是否授权了相册权限
|
||||
if (settingResult.authSetting &&
|
||||
(settingResult.authSetting['scope.writePhotosAlbum'] ||
|
||||
settingResult.authSetting['scope.camera'])) {
|
||||
if (settingResult.authSetting &&
|
||||
(settingResult.authSetting['scope.writePhotosAlbum'] ||
|
||||
settingResult.authSetting['scope.camera'])) {
|
||||
Taro.showToast({
|
||||
title: '授权成功',
|
||||
icon: 'success',
|
||||
|
|
@ -501,14 +499,14 @@ export class BowongAISDK {
|
|||
|
||||
} catch (error) {
|
||||
console.error('选择并上传图片失败:', error);
|
||||
|
||||
|
||||
// 检查是否是授权被拒绝的错误
|
||||
if (this._isAuthorizationError(error)) {
|
||||
await this._handleAuthorizationError();
|
||||
// 用户重新授权后,递归调用自己重试
|
||||
return this.chooseAndGenerateImage(options);
|
||||
}
|
||||
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -541,41 +539,6 @@ export class BowongAISDK {
|
|||
return mimeTypes[extension] || 'application/octet-stream';
|
||||
}
|
||||
|
||||
private _getExt(type: string): string {
|
||||
const mimeTypes: Record<string, string> = {
|
||||
'image/jpeg': 'jpg',
|
||||
'image/png': 'png',
|
||||
'image/gif': 'gif',
|
||||
'image/webp': 'webp',
|
||||
'video/mp4': 'mp4',
|
||||
'video/quicktime': 'mov',
|
||||
'video/x-msvideo': 'avi'
|
||||
};
|
||||
return mimeTypes[type] || 'jpg';
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成文件名,确保包含正确的扩展名
|
||||
* @private
|
||||
*/
|
||||
private _generateFileName(filePath: string, name?: string, type?: string): string {
|
||||
// 如果提供了名称,使用提供的名称
|
||||
if (name) {
|
||||
// 检查名称是否包含扩展名
|
||||
if (name.includes('.')) {
|
||||
return name;
|
||||
}
|
||||
// 没有扩展名,需要添加
|
||||
const fileType = type || this._getMimeType(filePath);
|
||||
const extension = this._getExt(fileType);
|
||||
return `${name}.${extension}`;
|
||||
}
|
||||
|
||||
// 没有提供名称,自动生成
|
||||
const fileExtension = this._getFileExtension(filePath);
|
||||
return `upload_${Date.now()}.${fileExtension}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成图像
|
||||
* @param params 图像生成参数
|
||||
|
|
|
|||
Loading…
Reference in New Issue