租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

3 months ago
  1. exports.encodeCallback = function encodeCallback(reqParams, options) {
  2. reqParams.headers = reqParams.headers || {};
  3. if (!Object.prototype.hasOwnProperty.call(reqParams.headers, 'x-oss-callback')) {
  4. if (options.callback) {
  5. const json = {
  6. callbackUrl: encodeURI(options.callback.url),
  7. callbackBody: options.callback.body
  8. };
  9. if (options.callback.host) {
  10. json.callbackHost = options.callback.host;
  11. }
  12. if (options.callback.contentType) {
  13. json.callbackBodyType = options.callback.contentType;
  14. }
  15. if (options.callback.callbackSNI) {
  16. json.callbackSNI = options.callback.callbackSNI;
  17. }
  18. const callback = Buffer.from(JSON.stringify(json)).toString('base64');
  19. reqParams.headers['x-oss-callback'] = callback;
  20. if (options.callback.customValue) {
  21. const callbackVar = {};
  22. Object.keys(options.callback.customValue).forEach(key => {
  23. callbackVar[`x:${key}`] = options.callback.customValue[key].toString();
  24. });
  25. reqParams.headers['x-oss-callback-var'] = Buffer.from(JSON.stringify(callbackVar)).toString('base64');
  26. }
  27. }
  28. }
  29. };