refactor
/ build (push) Successful in 44s

This commit is contained in:
2025-12-19 07:33:54 -08:00
parent a28d00a1fe
commit 0a244be9bb
10 changed files with 2067 additions and 2621 deletions
+25
View File
@@ -0,0 +1,25 @@
on:
push:
tags: [ '*' ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: latest
- name: Install Worker Dependencies
run: npm ci
- run: npm run deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- run: npm version from-git --allow-same-version --no-git-tag-version
- run: npm config set registry https://gitea.sugoidogo.com/api/packages/sugoidogo/npm/
- run: npm config set -- '//gitea.sugoidogo.com/api/packages/sugoidogo/npm/:_authToken' "$PACKAGES_KEY"
env:
PACKAGES_KEY: ${{ secrets.PACKAGES_KEY }}
- run: npm publish
+2005 -2565
View File
File diff suppressed because it is too large Load Diff
+7 -8
View File
@@ -1,18 +1,17 @@
{ {
"name": "cloudflare-polly-proxy", "name": "@sugoidogo/cloudflare-polly-proxy",
"version": "0.0.0", "files": [
"private": true, "static"
],
"main": "static/twitch-polly.js",
"scripts": { "scripts": {
"deploy": "wrangler deploy", "deploy": "wrangler deploy",
"dev": "wrangler dev", "test": "wrangler dev --ip localhost"
"start": "wrangler dev",
"test": "vitest"
}, },
"devDependencies": { "devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.1.0", "@cloudflare/vitest-pool-workers": "^0.1.0",
"@twurple/auth": "^7.2.1", "@twurple/auth": "^7.2.1",
"vitest": "1.3.0", "wrangler": "^4.56.0"
"wrangler": "^3.0.0"
}, },
"dependencies": { "dependencies": {
"aws4fetch": "^1.0.18" "aws4fetch": "^1.0.18"
+3 -3
View File
@@ -1,4 +1,3 @@
import jsmodule from '../static/twitch-polly.mjs'
import { AwsClient } from 'aws4fetch' import { AwsClient } from 'aws4fetch'
/** /**
@@ -36,9 +35,10 @@ export default {
} }
const url=new URL(request.url) const url=new URL(request.url)
if(url.pathname==='/twitch-polly.mjs'){ if(url.pathname==='/twitch-polly.mjs'){
return makeResponse(jsmodule,{ return makeResponse(undefined, {
status:308,
headers:{ headers:{
'content-type':'text/javascript' 'Location': url.href.replace('.mjs', '.js')
} }
}) })
} }
+2
View File
@@ -0,0 +1,2 @@
/*
access-control-allow-origin: *
@@ -56,7 +56,7 @@ export function DescribeVoices(
Engine='standard', Engine='standard',
LanguageCode='', LanguageCode='',
IncludeAdditionalLanguageCodes=true){ IncludeAdditionalLanguageCodes=true){
const url=new URL('/v1/voices',import.meta.url) const url=new URL('/v1/voices',origin)
url.search=new URLSearchParams({ url.search=new URLSearchParams({
Engine:Engine, Engine:Engine,
LanguageCode:LanguageCode, LanguageCode:LanguageCode,
@@ -160,7 +160,7 @@ export function SynthesizeSpeech(
Text+='</speak>' Text+='</speak>'
} }
} }
const url=new URL('/v1/speech',import.meta.url) const url=new URL('/v1/speech',origin)
url.search=new URLSearchParams({ url.search=new URLSearchParams({
Text:Text, Text:Text,
VoiceId:VoiceId, VoiceId:VoiceId,
@@ -184,8 +184,9 @@ export class Polly {
* *
* @param {import('@twurple/auth').AuthProvider} auth_provider * @param {import('@twurple/auth').AuthProvider} auth_provider
*/ */
constructor(auth_provider) { constructor(auth_provider,proxyOrigin=import.meta.url) {
this.#auth_provider = auth_provider this.#auth_provider = auth_provider
setProxyOrigin(proxyOrigin)
} }
async #GetAuthHeaders() { async #GetAuthHeaders() {
@@ -219,4 +220,10 @@ export class Polly {
SampleRate SampleRate
) )
} }
}
let origin = import.meta.url
export function setProxyOrigin(proxyOrigin) {
origin=proxyOrigin
} }
-20
View File
@@ -1,20 +0,0 @@
import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
import { describe, it, expect } from 'vitest';
import worker from '../src';
describe('Hello World worker', () => {
it('responds with Hello World! (unit style)', async () => {
const request = new Request('http://example.com');
// Create an empty context to pass to `worker.fetch()`.
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
await waitOnExecutionContext(ctx);
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
});
it('responds with Hello World! (integration style)', async () => {
const response = await SELF.fetch(request, env, ctx);
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
});
});
-11
View File
@@ -1,11 +0,0 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
export default defineWorkersConfig({
test: {
poolOptions: {
workers: {
wrangler: { configPath: './wrangler.toml' },
},
},
},
});
+15
View File
@@ -0,0 +1,15 @@
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "cloudflare-polly-proxy",
"main": "src/main.js",
"compatibility_date": "2024-06-05",
"compatibility_flags": ["nodejs_compat"],
"assets":{
"directory": "static"
},
"vars": {
"AWS_HOST":"https://polly.us-east-1.amazonaws.com"
},
"workers_dev": false,
"keep_vars": true
}
-11
View File
@@ -1,11 +0,0 @@
#:schema node_modules/wrangler/config-schema.json
name = "cloudflare-polly-proxy"
main = "src/index.js"
compatibility_date = "2024-06-05"
compatibility_flags = ["nodejs_compat"]
rules = [
{ type = "Data", globs = ["../static/*"], fallthrough = true }
]
[vars]
AWS_HOST = 'https://polly.us-east-1.amazonaws.com'