Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
try to send file
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Oct 13, 2024
1 parent 36261a6 commit a4aa3cf
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ jobs:
body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }}

artifact:
if: startsWith(github.ref, 'refs/heads/')
needs: [windows, macos, linux, windows7]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
run: npm install -g pnpm
- name: Install Dependencies
run: pnpm install
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Telegram Bot Server
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ secrets.TELEGRAM_BOT_API_ID }}
api_hash: ${{ secrets.TELEGRAM_BOT_API_HASH }}
- name: Upload Artifacts
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: pnpm artifact

updater:
if: startsWith(github.ref, 'refs/tags/v')
needs: [windows, macos, windows7]
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"updater": "node scripts/updater.mjs",
"checksum": "node scripts/checksum.mjs",
"telegram": "node scripts/telegram.mjs",
"artifact": "node scripts/artifact.mjs",
"dev": "electron-vite dev",
"postinstall": "electron-builder install-app-deps",
"build:win": "electron-vite build && electron-builder --publish never --win",
Expand Down Expand Up @@ -59,6 +60,7 @@
"electron-window-state": "^5.0.3",
"eslint": "^8.57.1",
"eslint-plugin-react": "^7.37.1",
"form-data": "^4.0.1",
"framer-motion": "^11.9.0",
"lodash": "^4.17.21",
"meta-json-schema": "^1.18.9",
Expand Down
13 changes: 8 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions scripts/artifact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import fs from 'fs'
import axios from 'axios'
import path from 'path'
import FormData from 'form-data'
import { fileURLToPath } from 'url'

const CHAT_ID = '@mihomo_party_group'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const pkg = fs.readFileSync('package.json', 'utf-8')
const { version } = JSON.parse(pkg)

const files = [
path.join(
__dirname,
`../mihomo-party-linux-${version}-aarch64.rpm
`
),
path.join(
__dirname,
`../mihomo-party-linux-${version}-arm64.deb
`
),
path.join(
__dirname,
`../mihomo-party-linux-${version}-x86_64.rpm
`
),
path.join(
__dirname,
`../mihomo-party-linux-${version}-amd64.deb
`
),
path.join(
__dirname,
`../mihomo-party-macos-${version}-arm64.dmg
`
),
path.join(
__dirname,
`../mihomo-party-macos-${version}-x64.dmg
`
),
path.join(
__dirname,
`../mihomo-party-windows-${version}-x64-setup.exe
`
),
path.join(
__dirname,
`../mihomo-party-windows-${version}-x64-portable.7z
`
),
path.join(
__dirname,
`../mihomo-party-win7-${version}-x64-setup.exe
`
),
path.join(
__dirname,
`../mihomo-party-win7-${version}-x64-portable.7z
`
)
]

const media = files.map((_, index) => ({
type: 'document',
media: `attach://file${index}`
}))

const form = new FormData()
form.append('chat_id', CHAT_ID)
form.append('media', JSON.stringify(media))

files.forEach((file, index) => {
form.append(`file${index}`, fs.createReadStream(file))
})

axios
.post(`http://127.0.0.1:8088/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`, form, {
headers: form.getHeaders()
})
.then((response) => {
console.log('Success:', response.data)
})
.catch((error) => {
console.error('Error:', error.response ? error.response.data : error.message)
})

0 comments on commit a4aa3cf

Please sign in to comment.