123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455 |
- const COS = require('../lib/cos-wx-sdk-v5');
- var wxfs = wx.getFileSystemManager();
- const config = require('../config');
- const { cos, requestCallback } = require('../tools');
- const picProcessDao = {
- 'uploadImg 上传时使用图片处理': uploadImg,
- 'requestImg 对云上数据进行图片处理': requestImg,
- 'getImg 下载时使用图片处理': getImg,
- '生成带图片处理参数的签名 URL': getObjectUrlWithPicProcess,
- '开通原图保护 openOriginProtect': openOriginProtect,
- '查询原图保护 describeOriginProtect': describeOriginProtect,
- '关闭原图保护 closeOriginProtect': closeOriginProtect,
- '查询海报合成任务 describePosterProductionJob': describePosterProductionJob,
- '批量拉取海报合成任务 describePosterProductionJobList': describePosterProductionJobList,
- '取消海报合成任务 cancelPosterProductionJob': cancelPosterProductionJob,
- '提交海报合成任务 postPosterProductionJob': postPosterProductionJob,
- '查询海报合成模板 describePosterProductionTemplate': describePosterProductionTemplate,
- '查询海报合成模板列表 describePosterProductionTemplateList': describePosterProductionTemplateList,
- '删除海报合成模板 deletePosterProductionTemplate': deletePosterProductionTemplate,
- '上传海报合成模板 uploadPosterProductionTemplate': uploadPosterProductionTemplate,
- '开通 Guetzli 压缩 openImageGuetzli': openImageGuetzli,
- '查询 Guetzli 压缩 describeImageGuetzli': describeImageGuetzli,
- '关闭 Guetzli 压缩 closeImageGuetzli': closeImageGuetzli,
- '提交图片处理任务 createImageProcessJob': createImageProcessJob,
- '创建图片处理模板 createImageProcessTemplate': createImageProcessTemplate,
- '更新图片处理模板 updateImageProcessTemplate': updateImageProcessTemplate,
- '新增图片样式 addImageStyle': addImageStyle,
- '查询图片样式 describeImageStyles': describeImageStyles,
- '删除图片样式 deleteImageStyles': deleteImageStyles,
- '异常图片检测同步请求 imageInspectSync': imageInspectSync,
- '创建异常图片检测任务 createImageInspectJob': createImageInspectJob,
- '开通图片处理异步服务 openImageProcessService': openImageProcessService,
- '查询图片处理异步服务 describeImageProcessService': describeImageProcessService,
- '关闭图片处理异步服务 closeImageProcessService': closeImageProcessService,
- '查询图片处理异步队列 describeImageProcessQueue': describeImageProcessQueue,
- '更新图片处理异步队列 updateImageProcessQueue': updateImageProcessQueue,
- '开通极智压缩 openImageSlim': openImageSlim,
- '查询极智压缩状态 describeImageSlim': describeImageSlim,
- '关闭极智压缩 closeImageSlim': closeImageSlim,
- '通过API使用极智压缩 imageSlim': imageSlim,
- '获取原图 getOriginImage': getOriginImage,
- 'uploadImgAnimate 上传时合成动图': uploadImgAnimate,
- 'requestImgAnimate 对云上数据进行合成动图': requestImgAnimate,
- 'getImgAnimate 下载时使用合成动图': getImgAnimate,
- 'uploadImgWatermark 上传时使用图片水印': uploadImgWatermark,
- 'requestImgWatermark 对云上数据使用图片水印': requestImgWatermark,
- 'getImgWatermark 下载时使用图片水印': getImgWatermark,
- 'uploadImgWatermarkText 上传时使用文字水印': uploadImgWatermarkText,
- 'requestImgWatermarkText 对云上数据使用文字水印': requestImgWatermarkText,
- 'getImgWatermarkText 下载时使用文字水印': getImgWatermarkText,
- 'uploadImgCompress 上传时使用图片压缩': uploadImgCompress,
- 'requestImgCompress 对云上数据使用图片压缩': requestImgCompress,
- 'getImgCompress 下载时使用图片压缩': getImgCompress,
- };
- function uploadImg() {
- wx.chooseMessageFile({
- count: 10,
- type: 'all',
- success: function (res) {
- var file = res.tempFiles[0];
- wxfs.readFile({
- filePath: file.path,
- success: function (res) {
- cos.putObject(
- {
- Bucket: config.Bucket, // Bucket 格式:test-1250000000
- Region: config.Region,
- Key: file.name,
- Body: res.data,
- Headers: {
- // 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',
- },
- },
- requestCallback
- );
- },
- fail: (err) => console.error(err),
- });
- },
- fail: (err) => console.error(err),
- });
- }
- function requestImg() {
- cos.request(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: 'photo.png',
- Method: 'POST',
- Action: 'image_process',
- Headers: {
- // 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',
- },
- },
- requestCallback
- );
- }
- function getImg() {
- cos.getObject(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: '1.png',
- QueryString: `imageMogr2/thumbnail/200x/`,
- },
- requestCallback
- );
- }
- function getObjectUrlWithPicProcess() {
- // 生成带图片处理参数的文件签名URL,过期时间设置为 30 分钟。
- cos.getObjectUrl(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: 'photo.png',
- QueryString: `imageMogr2/thumbnail/200x/`,
- Expires: 1800,
- Sign: true,
- },
- (err, data) => {
- console.log('带签名', err || data);
- }
- );
- // 生成带图片处理参数的文件URL,不带签名。
- cos.getObjectUrl(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: 'photo.png',
- QueryString: `imageMogr2/thumbnail/200x/`,
- Sign: false,
- },
- (err, data) => {
- console.log('不带签名', err || data);
- }
- );
- }
- function openOriginProtect() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
- const url = 'https://' + host;
- cos.request(
- {
- Method: 'PUT',
- Url: url,
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describeOriginProtect() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
- const url = 'https://' + host;
- cos.request(
- {
- Method: 'GET',
- Url: url,
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function closeOriginProtect() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
- const url = 'https://' + host;
- cos.request(
- {
- Method: 'DELETE',
- Url: url,
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describePosterProductionJob() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const jobId = 'xxx';
- const key = `pic_jobs/${jobId}`; // jobId:{jobId};
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describePosterProductionJobList() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = `pic_jobs`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Query: {
- // 拉取该队列 ID 下的任务;是否必传:是
- queueId: 'xxx',
- // 任务的 Tag;是否必传:是
- tag: 'PosterProduction',
- // 触发该任务的工作流ID;是否必传:否
- workflowId: '',
- // 触发该任务的存量触发任务ID;是否必传:否
- inventoryTriggerJobId: '',
- // 该任务的输入文件名,暂仅支持精确匹配;是否必传:否
- inputObject: '',
- // Desc 或者 Asc。默认为 Desc;是否必传:否
- orderByTime: 'Desc',
- // 请求的上下文,用于翻页。上次返回的值;是否必传:否
- nextToken: '',
- // 拉取该状态的任务,以,分割,支持多状态:All、Submitted、Running、Success、Failed、Pause、Cancel。默认为 All;是否必传:否
- states: 'All',
- // 拉取创建时间大于该时间的任务。格式为:%Y-%m-%dT%H:%m:%S%z,示例:2001-01-01T00:00:00+0800;是否必传:否
- // startCreationTime: "",
- // 拉取创建时间小于该时间的任务。格式为:%Y-%m-%dT%H:%m:%S%z,示例:2001-01-01T23:59:59+0800;是否必传:否
- // endCreationTime: "",
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function cancelPosterProductionJob() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const jobId = 'xxx';
- const key = `jobs/${jobId}?cancel`; // jobId:{jobId};
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'PUT', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function postPosterProductionJob() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = `pic_jobs`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 创建任务的 Tag:PicProcess;是否必传:是
- Tag: 'PosterProduction',
- // 待操作的媒体信息;是否必传:是
- Input: {
- // 媒体文件名;是否必传:是
- Object: '1.jpeg ',
- },
- // 操作规则;是否必传:是
- Operation: {
- // 指定该任务的参数;是否必传:否
- PosterProduction: {
- // ;是否必传:是
- TemplateId: 'xxx',
- Info: {
- main: 'https://examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/1.jpeg',
- text_main: 'demo',
- },
- },
- // 结果输出地址;是否必传:是
- Output: {
- // 存储桶的地域;是否必传:是
- Region: config.Region,
- // 存储结果的存储桶;是否必传:是
- Bucket: config.Bucket,
- // 结果文件的名字;是否必传:是
- Object: 'test.jpg',
- },
- // 透传用户信息, 可打印的 ASCII 码, 长度不超过1024;是否必传:否
- UserData: '',
- // 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
- JobLevel: '0',
- },
- // 任务所在的队列 ID;是否必传:否
- QueueId: '',
- // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
- CallBackFormat: '',
- // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
- CallBackType: 'Url',
- // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
- CallBack: '',
- },
- });
- cos.request(
- {
- Method: 'POST', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describePosterProductionTemplate() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const TemplateId = 'xxx';
- const key = `posterproduction/template/${TemplateId}`; // TemplateId:{TemplateId};
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describePosterProductionTemplateList() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = `posterproduction/template`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Query: {
- // 模板分类ID,支持传入多个,以,符号分割字符串;是否必传:否
- categoryIds: '',
- // Official(系统预设模板),Custom(自定义模板),All(所有模板),默认值: Custom;是否必传:否
- type: 'Custom',
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function deletePosterProductionTemplate() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const TemplateId = 'xxx';
- const key = `posterproduction/template/${TemplateId}`; // TemplateId:{TemplateId};
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'DELETE', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function uploadPosterProductionTemplate() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = `posterproduction/template`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 输入参数;是否必传:否
- Input: {
- // COS 桶中 PSD 文件,大小限制100M;是否必传:是
- Object: 'test.psd',
- },
- // 模板名称;是否必传:是
- Name: 'test',
- // 模板分类 ID,支持传入多个,以 , 符号分割字符串;是否必传:否
- CategoryIds: '',
- },
- });
- cos.request(
- {
- Method: 'POST', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function openImageGuetzli() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'PUT', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'guetzli', // 固定值
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describeImageGuetzli() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'guetzli', // 固定值
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function closeImageGuetzli() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'DELETE', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'guetzli', // 固定值
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function createImageProcessJob() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = `jobs`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 创建任务的 Tag:PicProcess;是否必传:是
- Tag: 'PicProcess',
- // 待操作的文件信息;是否必传:是
- Input: {
- // 文件路径;是否必传:是
- Object: '1.jpeg',
- },
- // 操作规则;是否必传:是
- Operation: {
- // 图片处理模板 ID;是否必传:否
- TemplateId: 'xxx',
- // 结果输出配置;是否必传:是
- Output: {
- // 存储桶的地域;是否必传:是
- Region: config.Region,
- // 存储结果的存储桶;是否必传:是
- Bucket: config.Bucket,
- // 结果文件的名字;是否必传:是
- Object: 'output/1.jpeg',
- },
- // 透传用户信息,可打印的 ASCII 码,长度不超过1024;是否必传:否
- UserData: '',
- // 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
- JobLevel: '0',
- },
- // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
- CallBackFormat: '',
- // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
- CallBackType: 'Url',
- // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
- CallBack: '',
- },
- });
- cos.request(
- {
- Method: 'POST', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function createImageProcessTemplate() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
- const key = `template`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 模板类型:PicProcess;是否必传:是
- Tag: 'PicProcess',
- // 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64;是否必传:是
- Name: 'test',
- // 图片处理参数;是否必传:是
- PicProcess: {
- // 是否返回原图信息,取值 true/false;是否必传:否
- IsPicInfo: '',
- // 图片处理规则基础图片处理参见 基础图片处理文档图片压缩参见 图片压缩 文档盲水印参见 盲水印 文档;是否必传:是
- ProcessRule: 'imageMogr2/rotate/9',
- },
- },
- });
- cos.request(
- {
- Method: 'POST', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function updateImageProcessTemplate() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const TemplateId = 'xxx';
- const key = `template/${TemplateId}`; // TemplateId:{TemplateId};
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 模板类型:PicProcess;是否必传:是
- Tag: 'PicProcess',
- // 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64;是否必传:是
- Name: 'test',
- // 图片处理参数;是否必传:是
- PicProcess: {
- // 是否返回原图信息,取值 true/false;是否必传:否
- IsPicInfo: '',
- // 图片处理规则基础图片处理参见 基础图片处理文档图片压缩参见 图片压缩 文档盲水印参见 盲水印 文档;是否必传:是
- ProcessRule: 'imageMogr2/rotate/99',
- },
- },
- });
- cos.request(
- {
- Method: 'PUT', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function addImageStyle() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- AddStyle: {
- // 样式名称;是否必传:是
- StyleName: 'test',
- // 样式详情;是否必传:是
- StyleBody: 'imageMogr2/thumbnail/!50px',
- },
- });
- cos.request(
- {
- Method: 'PUT', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'style', // 固定值
- Body: body,
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describeImageStyles() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'style', // 固定值
- Query: {
- GetStyle: {
- // 查询的图片样式名称。;是否必传:否
- StyleName: 'test',
- },
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function deleteImageStyles() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- DeleteStyle: {
- // 样式名称;是否必传:是
- StyleName: 'test',
- },
- });
- cos.request(
- {
- Method: 'DELETE', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'style', // 固定值
- Body: body,
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function imageInspectSync() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const ObjectKey = 'test.jpg';
- const key = `${ObjectKey}`; // ObjectKey:{ObjectKey};
- const host = `${config.Bucket}.cos.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Query: {
- // ;是否必传:是
- 'ci-process': 'ImageInspect',
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function createImageInspectJob() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = `jobs`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 创建任务的 Tag:ImageInspect;是否必传:是
- Tag: 'ImageInspect',
- // 待操作的文件信息;是否必传:是
- Input: {
- // 文件路径;是否必传:是
- Object: 'test.jpg',
- },
- // 操作规则;是否必传:否
- Operation: {
- // 透传用户信息,可打印的 ASCII 码,长度不超过1024;是否必传:否
- UserData: '',
- // 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
- JobLevel: '0',
- // 该任务的参数;是否必传:否
- ImageInspect: {
- // 是否开启识别到图片异常后自动对图片进行如移动到其他目录、设置为私有权限、删除等动作。取值:true/false,默认为false;是否必传:否
- AutoProcess: '',
- // 指定检测到异常图片后的处理动作BackupObject:将图片移动 abnormal_images_backup下,该目录由后台自动创建SwitchObjectToPrivate:将图片权限设置为私有DeleteObject:删除图片默认值:BackupObject当 AutoProcess 为 true 时,该参数生效;是否必传:否
- ProcessType: '',
- },
- },
- // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
- CallBackFormat: '',
- // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
- CallBackType: 'Url',
- // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
- CallBack: '',
- },
- });
- cos.request(
- {
- Method: 'POST', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function openImageProcessService() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = `picbucket`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'POST', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describeImageProcessService() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = `picbucket`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Query: {
- // 地域信息,以“,”分隔字符串,支持 All、ap-shanghai、ap-beijing;是否必传:否
- regions: '',
- // 存储桶名称,以“,”分隔,支持多个存储桶,精确搜索;是否必传:否
- bucketNames: '',
- // 存储桶名称前缀,前缀搜索;是否必传:否
- bucketName: 'test',
- // 第几页;是否必传:否
- pageNumber: '',
- // 每页个数;是否必传:否
- pageSize: '',
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function closeImageProcessService() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = `picbucket`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'DELETE', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describeImageProcessQueue() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = `picqueue`; //
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Query: {
- // 队列 ID,以“,”符号分割字符串;是否必传:否
- queueIds: '',
- // Active 表示队列内的作业会被调度执行Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响;是否必传:否
- state: 'Active',
- // 第几页,默认值1;是否必传:否
- pageNumber: '',
- // 每页个数,默认值10;是否必传:否
- pageSize: '',
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function updateImageProcessQueue() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const queueId = 'xxx';
- const key = `picqueue/${queueId}`; // queueId:{queueId};
- const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- Request: {
- // 队列名称,仅支持中文、英文、数字、_、-和*,长度不超过 128;是否必传:是
- Name: 'xxx',
- // Active 表示队列内的作业会被调度执行Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响;是否必传:是
- State: 'Active',
- // 回调配置;是否必传:是
- NotifyConfig: {
- // 回调开关OffOn;是否必传:否
- State: 'Off',
- // 回调事件TaskFinish:任务完成WorkflowFinish:工作流完成;是否必传:否
- // Event: "",
- // 回调格式XMLJSON;是否必传:否
- // ResultFormat: "",
- // 回调类型UrlTDMQ;是否必传:否
- // Type: "",
- // 回调地址,不能为内网地址。;是否必传:否
- // Url: "",
- // TDMQ 使用模式Topic:主题订阅Queue: 队列服务;是否必传:否
- // MqMode: "",
- // TDMQ 所属园区,目前支持园区 sh(上海)、bj(北京)、gz(广州)、cd(成都)、hk(中国香港);是否必传:否
- // MqRegion: "",
- // TDMQ 主题名称;是否必传:否
- // MqName: "",
- },
- },
- });
- cos.request(
- {
- Method: 'PUT', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function openImageSlim() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- const body = COS.util.json2xml({
- // 极智压缩配置信息
- ImageSlim: {
- // 极智压缩的使用模式,包含两种:API:开通极智压缩的 API 使用方式,开通后可在图片下载时通过极智压缩参数对图片进行压缩;Auto:开通极智压缩的自动使用方式,开通后无需携带任何参数,存储桶内指定格式的图片将在访问时自动进行极智压缩。注意:支持同时开通两种模式,多个值通过逗号分隔。
- SlimMode: 'Auto,API',
- // 当SlimMode的值包含Auto时生效,用于指定需要自动进行压缩的图片格式。
- Suffixs: {
- // 需要自动进行压缩的图片格式,可选值:jpg、png。
- Suffix: 'jpg',
- },
- },
- });
- cos.request(
- {
- Method: 'PUT', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'image-slim', // 固定值
- Body: body, // 请求体参数,必须
- ContentType: 'application/xml', // 固定值,必须
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function describeImageSlim() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'image-slim', // 固定值
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function closeImageSlim() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const key = ``; //
- const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'DELETE', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'image-slim', // 固定值
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function imageSlim() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const ObjectKey = 'test.jpeg';
- const key = `${ObjectKey}`; // ObjectKey:{ObjectKey};
- const host = `${config.Bucket}.cos.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Action: 'imageSlim', // 固定值
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function getOriginImage() {
- // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
- const ObjectKey = 'test.jpg';
- const key = `${ObjectKey}`; // ObjectKey:{ObjectKey};
- const host = `${config.Bucket}.cos.${config.Region}.myqcloud.com`;
- const url = `https://${host}/${key}`;
- cos.request(
- {
- Method: 'GET', // 固定值,必须
- Key: key, // 必须
- Url: url, // 请求的url,必须
- Query: {
- // 万象通用参数,需要获取原图的时,该参数固定为:originImage;是否必传:是
- 'ci-process': 'originImage',
- },
- },
- function (err, data) {
- if (err) {
- // 处理请求失败
- console.log(err);
- } else {
- // 处理请求成功
- console.log(data.Response);
- }
- }
- );
- }
- function uploadImgAnimate() {
- wx.chooseMessageFile({
- count: 2,
- type: 'all',
- success: function (res) {
- var file = res.tempFiles[0];
- wxfs.readFile({
- filePath: file.path,
- success: function (res) {
- cos.putObject(
- {
- Bucket: config.Bucket, // Bucket 格式:test-1250000000
- Region: config.Region,
- Key: file.name,
- Body: res.data,
- Headers: {
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "imageMogr2/animate/duration/10/images/<imageurl1>"}]}',
- },
- },
- requestCallback
- );
- },
- fail: (err) => console.error(err),
- });
- },
- fail: (err) => console.error(err),
- });
- }
- function requestImgAnimate() {
- // 对云上数据进行图片处理
- cos.request(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: '1.jpeg',
- Method: 'POST',
- Action: 'image_process',
- Headers: {
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "imageMogr2/animate/duration/10/images/<imageurl1>"}]}',
- },
- },
- requestCallback
- );
- }
- function getImgAnimate() {
- cos.getObject(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: '1.png',
- QueryString: `imageMogr2/animate/duration/10/images/<imageurl1>`,
- },
- requestCallback
- );
- }
- function uploadImgWatermark() {
- wx.chooseMessageFile({
- count: 2,
- type: 'all',
- success: function (res) {
- var file = res.tempFiles[0];
- wxfs.readFile({
- filePath: file.path,
- success: function (res) {
- cos.putObject(
- {
- Bucket: config.Bucket, // Bucket 格式:test-1250000000
- Region: config.Region,
- Key: file.name,
- Body: res.data,
- Headers: {
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/1/image/<encodedURL>/gravity/SouthEast/dx/10/dy/10/blogo/1"}]}',
- },
- },
- requestCallback
- );
- },
- fail: (err) => console.error(err),
- });
- },
- fail: (err) => console.error(err),
- });
- }
- function requestImgWatermark() {
- // 对云上数据进行图片处理
- cos.request(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: '1.jpeg',
- Method: 'POST',
- Action: 'image_process',
- Headers: {
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/1/image/<encodedURL>/gravity/SouthEast/dx/10/dy/10/blogo/1"}]}',
- },
- },
- requestCallback
- );
- }
- function getImgWatermark() {
- cos.getObject(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: 'test.jpg',
- QueryString: `watermark/1/image/<encodedURL>/gravity/SouthEast/dx/10/dy/10/blogo/1`,
- },
- requestCallback
- );
- }
- function uploadImgWatermarkText() {
- wx.chooseMessageFile({
- count: 2,
- type: 'all',
- success: function (res) {
- var file = res.tempFiles[0];
- wxfs.readFile({
- filePath: file.path,
- success: function (res) {
- cos.putObject(
- {
- Bucket: config.Bucket, // Bucket 格式:test-1250000000
- Region: config.Region,
- Key: file.name,
- Body: res.data,
- Headers: {
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/2/text/5paH5a2X5rC05Y2w5rWL6K-V/fontsize/16/dissolve/100/gravity/SouthEast/dx/10/dy/10/batch/1/degree/45/shadow/50"}]}',
- },
- },
- requestCallback
- );
- },
- fail: (err) => console.error(err),
- });
- },
- fail: (err) => console.error(err),
- });
- }
- function requestImgWatermarkText() {
- // 对云上数据进行图片处理
- cos.request(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: '1.jpeg',
- Method: 'POST',
- Action: 'image_process',
- Headers: {
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/2/text/5paH5a2X5rC05Y2w5rWL6K-V/fontsize/16/dissolve/100/gravity/SouthEast/dx/10/dy/10/batch/1/degree/45/shadow/50"}]}',
- },
- },
- requestCallback
- );
- }
- function getImgWatermarkText() {
- cos.getObject(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: 'test.jpg',
- QueryString: `watermark/2/text/5paH5a2X5rC05Y2w5rWL6K-V/fontsize/16/dissolve/100/gravity/SouthEast/dx/10/dy/10/batch/1/degree/45/shadow/50`,
- },
- requestCallback
- );
- }
- function uploadImgCompress() {
- wx.chooseMessageFile({
- count: 2,
- type: 'all',
- success: function (res) {
- var file = res.tempFiles[0];
- wxfs.readFile({
- filePath: file.path,
- success: function (res) {
- cos.putObject(
- {
- Bucket: config.Bucket, // Bucket 格式:test-1250000000
- Region: config.Region,
- Key: file.name,
- Body: res.data,
- Headers: {
- // 通过 imageMogr2 接口进行 webp 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject.jpg", "rule": "imageMogr2/format/webp"}]}',
- },
- },
- requestCallback
- );
- },
- fail: (err) => console.error(err),
- });
- },
- fail: (err) => console.error(err),
- });
- }
- function requestImgCompress() {
- // 对云上数据进行图片处理
- cos.request(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: '1.jpeg',
- Method: 'POST',
- Action: 'image_process',
- Headers: {
- // 通过 imageMogr2 接口进行 webp 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
- 'Pic-Operations':
- '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject.jpeg", "rule": "imageMogr2/format/webp"}]}',
- },
- },
- requestCallback
- );
- }
- function getImgCompress() {
- cos.getObject(
- {
- Bucket: config.Bucket,
- Region: config.Region,
- Key: 'test.jpg',
- QueryString: `imageMogr2/format/webp`, // 通过 imageMogr2 接口进行 webp 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
- },
- requestCallback
- );
- }
- module.exports = picProcessDao;
|