Skip to content

Commit

Permalink
add ireadnote import
Browse files Browse the repository at this point in the history
  • Loading branch information
yy4382 committed Feb 4, 2024
1 parent e5b4a4e commit 0abcaa9
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
52 changes: 52 additions & 0 deletions api/ireadnote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Request, Response } from "express";
function generateRandomString(length: number): string {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(
Math.floor(Math.random() * charactersLength)
);
}
return result;
}

module.exports = async (request: Request, response: Response) => {
console.log("Import url: " + request.url);
const api = request.query["api"];
const name = request.query["name"];
const voiceName = request.query["voiceName"] ?? "zh-CN-XiaoxiaoNeural";
const token = request.query["token"] ?? "";

const config = {
loginUrl: "",
_ClassName: "JxdAdvCustomTTS",
_TTSConfigID: generateRandomString(16),
httpConfigs: {
headers: {},
},
ttsHandles: [
{
forGetMethod: 1,
processType: 1,
params: {
text: "%@",
voiceName: voiceName,
},
url: api,
parser: {
playData: "ResponseData",
},
httpConfigs: {
useCookies: 1,
headers: {
authorization: `Bearer ${token}`,
},
},
},
],
_TTSName: name,
};
response.status(200).json(config);
};
1 change: 1 addition & 0 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ app.use(express.static('public'))
app.get('/api/legado', require('./api/legado'))
app.post('/api/ra', require('./api/ra'))
app.get('/api/aiyue', require('./api/aiyue'))
app.get('/api/ireadnote', require('./api/ireadnote'))
app.listen(port, () => {
console.info(`应用正在监听 ${port} 端口`)
})
52 changes: 48 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" target="_blank" href="https://github.com/yy4382/ms-ra-forwarder-for-ifreetime">ms-ra-forwarder-for-ifreetime</a>
<ul class="navbar-nav d-flex justify-content-between align-items-center">
<ul class="navbar-nav d-flex flex-row justify-content-between align-items-center">
<li class="nav-item">
<a class="github-button" href="https://github.com/yy4382/ms-ra-forwarder-for-ifreetime" data-size="large"
data-show-count="true" aria-label="Star yy4382/ms-ra-forwarder-for-ifreetime on GitHub">本项目 Star</a>
Expand Down Expand Up @@ -96,8 +96,10 @@
<div class="col">
<button id="previewButton" type="button" class="btn btn-secondary" onclick="preview()">测试</button>
<button type="button" class="btn btn-primary" onclick='createLegadoUrl()'>生成阅读(legado)语音引擎链接</button>
<button type="button" class="btn btn-primary" onclick='createIReadUrl()'>生成爱阅记导入链接</button>
</div>
</div>
</div>
</form>
<div style="height:50px"></div>
</div>
Expand All @@ -123,6 +125,29 @@ <h5 class="modal-title">阅读链接</h5>
</div>
</div>
</div>
<div id="iReadUrlModal" class="modal " tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">爱阅记链接</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="iReadUrlQRCode" style="text-align:center">
</div>
<div class="row">
<p>音频格式暂时未支持。</p>
</div>
<div class="row">
<textarea id="iReadUrl" class="form-control" readonly rows="3" cols="2" value></textarea>
</div>
<div class="row" style="margin-top: 10px;">
<a id="iReadImportButton" class="btn btn-primary" href="">一键导入到爱阅记</a>
</div>
</div>
</div>
</div>
</div>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
Expand All @@ -146,16 +171,16 @@ <h5 class="modal-title">阅读链接</h5>
});

function refreshVoice() {
let voiceElelement = document.getElementsByName('voiceName')[0];
voiceElelement.innerHTMl = '';
let voiceElement = document.getElementsByName('voiceName')[0];
voiceElement.innerHTMl = '';
voices.forEach(item => {
let option = document.createElement('option');
option.value = item['ShortName'];
option.innerText = item['FriendlyName'];
if (item['ShortName'] == 'zh-CN-XiaoxiaoNeural') {
option.selected = true;
}
voiceElelement.append(option)
voiceElement.append(option)
});
updateConfigName();
}
Expand Down Expand Up @@ -240,6 +265,25 @@ <h5 class="modal-title">阅读链接</h5>
document.getElementById('legadoUrl').value = url;
document.getElementById('legadoImportButton').href = 'legado://import/httpTTS?src=' + encodeURIComponent(url);
}
function createIReadUrl() {
let name = document.getElementsByName('name')[0].value;
let voiceName = document.getElementsByName('voiceName')[0].value;
let voiceFormat = document.getElementsByName('voiceFormat')[0].value;
let token = document.getElementsByName('token')[0].value;
let previewText = document.getElementsByName('previewText')[0].value;
let url = window.location.protocol + '//' + window.location.host + '/api/ireadnote'
+ '?api=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + '/api/aiyue')
+ '&name=' + encodeURIComponent(name)
+ '&voiceName=' + encodeURIComponent(voiceName)
// + '&voiceFormat=' + encodeURIComponent(voiceFormat)
+ '&token=' + encodeURIComponent(token);
let svg = new QRCode(url).svg();
let modal = new bootstrap.Modal(document.getElementById('iReadUrlModal'))
modal.show();
document.getElementById('iReadUrlQRCode').innerHTML = svg;
document.getElementById('iReadUrl').value = url;
document.getElementById('iReadImportButton').href = 'iReadNote://import/itts=' + url;
}
</script>
</body>

Expand Down

0 comments on commit 0abcaa9

Please sign in to comment.