@anjir/app-novinhub
Version:
نوین هاب - پلتفرم کامل مدیریت شبکههای اجتماعی، دایرکت هوشمند، و خودکارسازی پیامرسانی
56 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.novinhubUploadFileAction = void 0;
const apps_framework_1 = require("@anjir/apps-framework");
const apps_common_1 = require("@anjir/apps-common");
const index_1 = require("../../index");
const common_1 = require("../common");
exports.novinhubUploadFileAction = (0, apps_framework_1.createAction)({
auth: index_1.novinhubAuth,
name: 'upload_file',
displayName: 'آپلود فایل',
description: 'آپلود فایل جدید به نوین هاب',
props: {
file: apps_framework_1.Property.File({
displayName: 'فایل',
description: 'فایلی که میخواهید آپلود کنید',
required: true,
}),
},
async run(ctx) {
const { file } = ctx.propsValue;
const headers = {
'Authorization': `Bearer ${ctx.auth.access_token}`,
};
const url = (0, common_1.buildApiUrl)('/file');
try {
// Create FormData for file upload
const formData = new FormData();
formData.append('file', new Blob([file.data]), file.filename);
const response = await apps_common_1.httpClient.sendRequest({
method: apps_common_1.HttpMethod.POST,
url: url,
headers: headers,
body: formData,
});
if (response.status === 200 || response.status === 201) {
return {
success: true,
file: response.body,
message: 'فایل با موفقیت آپلود شد',
};
}
else {
throw new Error(`خطا در آپلود فایل: ${response.body?.message || `HTTP ${response.status}`}`);
}
}
catch (error) {
const errorMessage = error.message || error.toString() || 'خطا در آپلود فایل';
return {
success: false,
error: errorMessage,
};
}
},
});
//# sourceMappingURL=upload-file.js.map