From 37d3f27ef57b72b6b818af6749174d53d759da6a Mon Sep 17 00:00:00 2001 From: qxa Date: Wed, 21 Feb 2024 16:19:02 +0800 Subject: [PATCH] first commit --- action.yaml | 18 ++++++ dist/index.js | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 44 ++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 action.yaml create mode 100644 dist/index.js create mode 100644 index.js diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..0fccad7 --- /dev/null +++ b/action.yaml @@ -0,0 +1,18 @@ +name: webhook +description: send webhook +author: qxa + +inputs: + urls: + description: 要推送的url列表 + required: true + content_type: + description: 请求类型 + default: application/json + template: + required: true + description: 发送内容 + +runs: + using: node16 + main: dist/index.js diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..a8315ec --- /dev/null +++ b/dist/index.js @@ -0,0 +1,164 @@ +module.exports = +/******/ (function(modules, runtime) { // webpackBootstrap +/******/ "use strict"; +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ var threw = true; +/******/ try { +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ threw = false; +/******/ } finally { +/******/ if(threw) delete installedModules[moduleId]; +/******/ } +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ __webpack_require__.ab = __dirname + "/"; +/******/ +/******/ // the startup function +/******/ function startup() { +/******/ // Load entry module and return exports +/******/ return __webpack_require__(571); +/******/ }; +/******/ // initialize runtime +/******/ runtime(__webpack_require__); +/******/ +/******/ // run startup +/******/ return startup(); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ 211: +/***/ (function(module) { + +module.exports = require("https"); + +/***/ }), + +/***/ 571: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(605); +/* harmony import */ var http__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(http__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var https__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(211); +/* harmony import */ var https__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(https__WEBPACK_IMPORTED_MODULE_1__); + + + +console.log(process.env) + +const urls = process.env.INPUT_URLS.replace('\n', ' ').trim().replace(/\s+/, ',').split(',').filter(s => s) +const content_type = process.env.INPUT_CONTENT_TYPE.trim() +const template = process.env.INPUT_TEMPLATE.trim() + +urls.forEach(item => { + let request = undefined + if (item.startsWith('http://')) { + request = http__WEBPACK_IMPORTED_MODULE_0__.http_request + } else if (item.startsWith('https://')) { + request = https__WEBPACK_IMPORTED_MODULE_1__.https_request + } + + if (request) { + // 设置请求选项 + const options = { + method: 'POST', // HTTP请求方法 + headers: { + 'Content-Type': content_type, // 指定请求体类型为JSON格式 + 'Content-Length': Buffer.byteLength(template) // 计算请求体长度 + } + }; + + // 创建HTTP客户端并发送POST请求 + const req = request(item, options, (res) => { + let data = ''; + + res.on('data', (chunk) => { + data += chunk; + }); + + res.on('end', () => { + console.log(`服务器返回结果:${data}`); + }); + }); + + req.write(template) // 将POST请求参数写入请求流中 + req.end() // 完成请求 + } +}) + + +/***/ }), + +/***/ 605: +/***/ (function(module) { + +module.exports = require("http"); + +/***/ }) + +/******/ }, +/******/ function(__webpack_require__) { // webpackRuntimeModules +/******/ "use strict"; +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ !function() { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ }(); +/******/ +/******/ /* webpack/runtime/compat get default export */ +/******/ !function() { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ }(); +/******/ +/******/ /* webpack/runtime/define property getter */ +/******/ !function() { +/******/ // define getter function for harmony exports +/******/ var hasOwnProperty = Object.prototype.hasOwnProperty; +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!hasOwnProperty.call(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ }(); +/******/ +/******/ } +); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..45e2abf --- /dev/null +++ b/index.js @@ -0,0 +1,44 @@ +import { http_request } from 'http' +import { https_request } from 'https' + +console.log(process.env) + +const urls = process.env.INPUT_URLS.replace('\n', ' ').trim().replace(/\s+/, ',').split(',').filter(s => s) +const content_type = process.env.INPUT_CONTENT_TYPE.trim() +const template = process.env.INPUT_TEMPLATE.trim() + +urls.forEach(item => { + let request = undefined + if (item.startsWith('http://')) { + request = http_request + } else if (item.startsWith('https://')) { + request = https_request + } + + if (request) { + // 设置请求选项 + const options = { + method: 'POST', // HTTP请求方法 + headers: { + 'Content-Type': content_type, // 指定请求体类型为JSON格式 + 'Content-Length': Buffer.byteLength(template) // 计算请求体长度 + } + }; + + // 创建HTTP客户端并发送POST请求 + const req = request(item, options, (res) => { + let data = ''; + + res.on('data', (chunk) => { + data += chunk; + }); + + res.on('end', () => { + console.log(`服务器返回结果:${data}`); + }); + }); + + req.write(template) // 将POST请求参数写入请求流中 + req.end() // 完成请求 + } +})