/** * 鍏朵粬demo闆嗗悎 */ // 寮€閫氭暟鎹竾璞� export const createCIBucket = { name: '寮€閫氭暟鎹竾璞�', fn: function createCIBucket() { const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`; const url = `https://${host}`; cos.request( { Method: 'PUT', // 鍥哄畾鍊硷紝蹇呴』 Url: url, // 璇锋眰鐨剈rl锛屽繀椤� }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data.Response); } } ); }, }; // 鍏抽棴鏁版嵁涓囪薄 export const deleteCIBucket = { name: '鍏抽棴鏁版嵁涓囪薄', fn: function deleteCIBucket() { const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`; const url = `https://${host}`; cos.request( { Method: 'PUT', // 鍥哄畾鍊硷紝蹇呴』 Url: url, // 璇锋眰鐨剈rl锛屽繀椤� Action: 'unbind', // 鍥哄畾鍊� }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data.Response); } } ); }, }; // 鏌ヨ鏌ヨ鏁版嵁澶勭悊鏈嶅姟 export const queryCIBucket = { name: '鏌ヨ鏌ヨ鏁版嵁澶勭悊鏈嶅姟', fn: function queryCIBucket() { const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`; const url = `https://${host}`; cos.request( { Method: 'GET', // 鍥哄畾鍊硷紝蹇呴』 Url: url, // 璇锋眰鐨剈rl锛屽繀椤� }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data); } } ); }, }; // 鎻愪氦鐥呮瘨妫€娴嬩换鍔� export const postVirusDetect = { name: '鎻愪氦鐥呮瘨妫€娴嬩换鍔�', fn: function postVirusDetect() { const host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/virus/detect'; const url = 'https://' + host; const body = COS.util.json2xml({ Request: { Input: { Object: 'test/1.png', // 鏂囦欢鍚嶏紝鍙栧€间负鏂囦欢鍦ㄥ綋鍓嶅瓨鍌ㄦ《涓殑瀹屾暣鍚嶇О锛屼笌Url鍙傛暟浜岄€変竴 // Url: 'http://examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/virus.doc', // 鐥呮瘨鏂囦欢鐨勯摼鎺ュ湴鍧€锛屼笌Object鍙傛暟浜岄€変竴 }, Conf: { DetectType: 'Virus', // 妫€娴嬬殑鐥呮瘨绫诲瀷锛屽綋鍓嶅浐瀹氫负锛歏irus // CallBack: 'http://callback.demo.com', // 浠诲姟鍥炶皟鐨勫湴鍧€ }, }, }); cos.request( { Method: 'POST', Key: 'virus/detect', Url: url, Body: body, ContentType: 'application/xml', }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data); } } ); }, }; // 鏌ヨ鐥呮瘨妫€娴嬩换鍔$粨鏋� export const getVirusDetectResult = { name: '鏌ヨ鐥呮瘨妫€娴嬩换鍔$粨鏋�', fn: function getVirusDetectResult() { const jobId = 'ssdb2dab23bcdb11ed9efb5254009411xx'; // 鎻愪氦鐥呮瘨妫€娴嬩换鍔″悗浼氳繑鍥炲綋鍓嶄换鍔$殑jobId const host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/virus/detect/' + jobId; const url = 'https://' + host; cos.request( { Method: 'GET', Key: 'virus/detect/' + jobId, Url: url, }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data); } } ); }, }; // 鏌ヨ闃茬洍閾� export const describeRefer = { name: '鏌ヨ闃茬洍閾�', fn: function describeRefer() { const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?hotlink'; const url = 'https://' + host; cos.request( { Method: 'GET', Url: url, }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data); } } ); }, }; // 璁剧疆闃茬洍閾� export const setRefer = { name: '璁剧疆闃茬洍閾�', fn: function setRefer() { const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?hotlink'; const url = 'https://' + host; const body = COS.util.json2xml({ Hotlink: { Url: 'https://www.example.com', // 蹇呴』锛屽煙鍚嶅湴鍧€ Type: 'white', // 蹇呴』锛岄槻鐩楅摼绫诲瀷锛寃hite 涓虹櫧鍚嶅崟锛宐lack 涓洪粦鍚嶅崟锛宱ff 涓哄叧闂€� }, }); cos.request( { Method: 'PUT', Url: url, Body: body, ContentType: 'application/xml', }, function (err, data) { if (err) { // 澶勭悊璇锋眰澶辫触 console.log(err); } else { // 澶勭悊璇锋眰鎴愬姛 console.log(data); } } ); }, };