@xuda.io/ai_module 1.1.4426 → 1.1.4428
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +3 -107
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2967,7 +2967,7 @@ const upload_agent_files = async function (uid, agent_doc) {
|
|
|
2967
2967
|
if (tool.type === 'file_search') {
|
|
2968
2968
|
if (!_.isEmpty(tool.file)) {
|
|
2969
2969
|
if (!tool.file.file_id) {
|
|
2970
|
-
const validation_ret = file_upload_validator(tool.file.name);
|
|
2970
|
+
const validation_ret = drive_module.file_upload_validator(tool.file.name);
|
|
2971
2971
|
if (!validation_ret.valid) {
|
|
2972
2972
|
throw new Error(validation_ret.error);
|
|
2973
2973
|
}
|
|
@@ -3766,110 +3766,6 @@ const download_yt_audio = function (videoUrl) {
|
|
|
3766
3766
|
});
|
|
3767
3767
|
};
|
|
3768
3768
|
|
|
3769
|
-
const file_upload_validator = function (file_name) {
|
|
3770
|
-
// 1. Safety check: ensure file_name exists
|
|
3771
|
-
if (!file_name || typeof file_name !== 'string') {
|
|
3772
|
-
return { valid: false, error: 'Invalid filename' };
|
|
3773
|
-
}
|
|
3774
|
-
|
|
3775
|
-
// 2. Extract the extension (remove dot and make lowercase)
|
|
3776
|
-
const ext = file_name.split('.').pop().toLowerCase();
|
|
3777
|
-
|
|
3778
|
-
// 3. Validate using Switch
|
|
3779
|
-
switch (ext) {
|
|
3780
|
-
// ==============================
|
|
3781
|
-
// VALIDATE AUDIO FILES
|
|
3782
|
-
// ==============================
|
|
3783
|
-
case 'mp3':
|
|
3784
|
-
return { valid: true, category: 'audio', mime: 'audio/mpeg' };
|
|
3785
|
-
case 'wav':
|
|
3786
|
-
return { valid: true, category: 'audio', mime: 'audio/wav' };
|
|
3787
|
-
case 'ogg':
|
|
3788
|
-
return { valid: true, category: 'audio', mime: 'audio/ogg' };
|
|
3789
|
-
case 'm4a':
|
|
3790
|
-
return { valid: true, category: 'audio', mime: 'audio/mp4' };
|
|
3791
|
-
|
|
3792
|
-
// ==============================
|
|
3793
|
-
// VALIDATE VIDEO FILES
|
|
3794
|
-
// ==============================
|
|
3795
|
-
case 'mp4':
|
|
3796
|
-
return { valid: true, category: 'video', mime: 'video/mp4' };
|
|
3797
|
-
case 'webm':
|
|
3798
|
-
return { valid: true, category: 'video', mime: 'video/webm' };
|
|
3799
|
-
case 'avi':
|
|
3800
|
-
return { valid: true, category: 'video', mime: 'video/x-msvideo' };
|
|
3801
|
-
case 'mov':
|
|
3802
|
-
return { valid: true, category: 'video', mime: 'video/quicktime' };
|
|
3803
|
-
|
|
3804
|
-
// ==============================
|
|
3805
|
-
// VALIDATE PICTURE FILES
|
|
3806
|
-
// ==============================
|
|
3807
|
-
case 'jpg':
|
|
3808
|
-
case 'jpeg':
|
|
3809
|
-
return { valid: true, category: 'image', mime: 'image/jpeg' };
|
|
3810
|
-
case 'png':
|
|
3811
|
-
return { valid: true, category: 'image', mime: 'image/png' };
|
|
3812
|
-
case 'gif':
|
|
3813
|
-
return { valid: true, category: 'image', mime: 'image/gif' };
|
|
3814
|
-
case 'svg':
|
|
3815
|
-
return { valid: true, category: 'image', mime: 'image/svg+xml' };
|
|
3816
|
-
case 'webp':
|
|
3817
|
-
return { valid: true, category: 'image', mime: 'image/webp' };
|
|
3818
|
-
|
|
3819
|
-
// ==============================
|
|
3820
|
-
// VALIDATE TEXT / CODE FILES
|
|
3821
|
-
// ==============================
|
|
3822
|
-
case 'c':
|
|
3823
|
-
return { valid: true, category: 'text', mime: 'text/x-c' };
|
|
3824
|
-
case 'cpp':
|
|
3825
|
-
return { valid: true, category: 'text', mime: 'text/x-c++' };
|
|
3826
|
-
case 'cs':
|
|
3827
|
-
return { valid: true, category: 'text', mime: 'text/x-csharp' };
|
|
3828
|
-
case 'css':
|
|
3829
|
-
return { valid: true, category: 'text', mime: 'text/css' };
|
|
3830
|
-
case 'doc':
|
|
3831
|
-
return { valid: true, category: 'document', mime: 'application/msword' };
|
|
3832
|
-
case 'docx':
|
|
3833
|
-
return { valid: true, category: 'document', mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' };
|
|
3834
|
-
case 'go':
|
|
3835
|
-
return { valid: true, category: 'text', mime: 'text/x-golang' };
|
|
3836
|
-
case 'html':
|
|
3837
|
-
return { valid: true, category: 'text', mime: 'text/html' };
|
|
3838
|
-
case 'java':
|
|
3839
|
-
return { valid: true, category: 'text', mime: 'text/x-java' };
|
|
3840
|
-
case 'js':
|
|
3841
|
-
return { valid: true, category: 'text', mime: 'text/javascript' };
|
|
3842
|
-
case 'json':
|
|
3843
|
-
return { valid: true, category: 'text', mime: 'application/json' };
|
|
3844
|
-
case 'md':
|
|
3845
|
-
return { valid: true, category: 'text', mime: 'text/markdown' };
|
|
3846
|
-
case 'pdf':
|
|
3847
|
-
return { valid: true, category: 'document', mime: 'application/pdf' };
|
|
3848
|
-
case 'php':
|
|
3849
|
-
return { valid: true, category: 'text', mime: 'text/x-php' };
|
|
3850
|
-
case 'pptx':
|
|
3851
|
-
return { valid: true, category: 'document', mime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' };
|
|
3852
|
-
case 'py':
|
|
3853
|
-
return { valid: true, category: 'text', mime: 'text/x-python' }; // or text/x-script.python
|
|
3854
|
-
case 'rb':
|
|
3855
|
-
return { valid: true, category: 'text', mime: 'text/x-ruby' };
|
|
3856
|
-
case 'sh':
|
|
3857
|
-
return { valid: true, category: 'text', mime: 'application/x-sh' };
|
|
3858
|
-
case 'tex':
|
|
3859
|
-
return { valid: true, category: 'text', mime: 'text/x-tex' };
|
|
3860
|
-
case 'ts':
|
|
3861
|
-
return { valid: true, category: 'text', mime: 'application/typescript' };
|
|
3862
|
-
case 'txt':
|
|
3863
|
-
return { valid: true, category: 'text', mime: 'text/plain' };
|
|
3864
|
-
|
|
3865
|
-
// ==============================
|
|
3866
|
-
// DEFAULT (INVALID)
|
|
3867
|
-
// ==============================
|
|
3868
|
-
default:
|
|
3869
|
-
return { valid: false, error: `Unsupported file extension: .${ext}` };
|
|
3870
|
-
}
|
|
3871
|
-
};
|
|
3872
|
-
|
|
3873
3769
|
export const upload_prompt_attachment = async function (req, job_id, headers, file_obj) {
|
|
3874
3770
|
const { uid } = req;
|
|
3875
3771
|
try {
|
|
@@ -3879,7 +3775,7 @@ export const upload_prompt_attachment = async function (req, job_id, headers, fi
|
|
|
3879
3775
|
|
|
3880
3776
|
const file_name = file_obj?.['originalname'];
|
|
3881
3777
|
|
|
3882
|
-
const validation_ret = file_upload_validator(file_name);
|
|
3778
|
+
const validation_ret = drive_module.file_upload_validator(file_name);
|
|
3883
3779
|
|
|
3884
3780
|
if (!validation_ret.valid) {
|
|
3885
3781
|
throw new Error(validation_ret.error);
|
|
@@ -6380,7 +6276,7 @@ const attachment_handler = async function (uid, app_id, conversation_id, attachm
|
|
|
6380
6276
|
return Buffer.concat(chunks);
|
|
6381
6277
|
}
|
|
6382
6278
|
|
|
6383
|
-
const validation_ret = file_upload_validator(filename);
|
|
6279
|
+
const validation_ret = drive_module.file_upload_validator(filename);
|
|
6384
6280
|
if (!validation_ret.valid) {
|
|
6385
6281
|
throw new Error(validation_ret.error);
|
|
6386
6282
|
}
|