fix: magnet invalid json

fix: torrent error "object Object"
fix: macos microphone notification prompt
fix: bring back error logging [oops]
This commit is contained in:
ThaUnknown 2024-06-16 16:32:27 +02:00
parent 31c371f828
commit 082444f2a7
5 changed files with 107 additions and 67 deletions

View file

@ -68,7 +68,11 @@ client.on('warn', ({ detail }) => {
export async function add (torrentID, hide) {
if (torrentID) {
console.info('Torrent: adding torrent', { torrentID })
localStorage.setItem('torrent', torrentID)
if (torrentID.startsWith?.('magnet:')) {
localStorage.setItem('torrent', JSON.stringify(torrentID))
} else {
localStorage.setItem('torrent', torrentID)
}
files.set([])
if (!hide) page.set('player')
client.send('torrent', torrentID)

View file

@ -27,6 +27,9 @@ const announce = [
let storedSettings = {}
// HACK: this is https only, but electron doesnt run in https
if (!globalThis.FileSystemFileHandle) global.FileSystemFileHandle = false
try {
storedSettings = JSON.parse(localStorage.getItem('settings')) || {}
} catch (error) {}
@ -112,15 +115,18 @@ export default class TorrentClient extends WebTorrent {
}
loadLastTorrent (t) {
if (!localStorage.getItem('torrent') && !t) return
let torrent = localStorage.getItem('torrent') && new Uint8Array(JSON.parse(localStorage.getItem('torrent')))
if (!torrent) {
// this can be a magnet string, or a stringified array, lazy way of makign sure it works
try {
torrent = new Uint8Array(JSON.parse(t))
} catch (e) {
torrent = t
if (!t) return
let torrent
// this can be a magnet string, or a stringified array, lazy way of makign sure it works
try {
const parsed = JSON.parse(t)
if (typeof parsed === 'string') {
torrent = parsed
} else {
torrent = new Uint8Array(parsed)
}
} catch (e) {
torrent = t
}
if (torrent) this.addTorrent(torrent, JSON.parse(localStorage.getItem('lastFinished')))
}
@ -144,10 +150,10 @@ export default class TorrentClient extends WebTorrent {
}
this.dispatch('files', files)
this.dispatch('magnet', { magnet: torrent.magnetURI, hash: torrent.infoHash })
localStorage.setItem('torrent', JSON.stringify([...torrent.torrentFile]))
localStorage.setItem('torrent', JSON.stringify([...torrent.torrentFile])) // this won't work on mobile, but really it only speeds stuff up by ~1-2 seconds since magnet data doesn't need to be resolved
if (torrent.length > await this.storageQuota(torrent.path)) {
this.dispatch('error', 'Torrent Too Big! This Torrent Exceeds The Selected Drive\'s Available Space. Change Download Location In Torrent Settings To A Drive With More Space And Restart The App!')
this.dispatchError('Torrent Too Big! This Torrent Exceeds The Selected Drive\'s Available Space. Change Download Location In Torrent Settings To A Drive With More Space And Restart The App!')
}
}
@ -190,7 +196,7 @@ export default class TorrentClient extends WebTorrent {
_scrape ({ id, infoHashes }) {
this.trackers.cat._request(this.trackers.cat.scrapeUrl, { info_hash: infoHashes.map(infoHash => hex2bin(infoHash)) }, (err, data) => {
if (err) {
this.dispatch('error', err)
this.dispatchError(err)
return this.dispatch('scrape', { id, result: [] })
}
const { files } = data
@ -203,12 +209,25 @@ export default class TorrentClient extends WebTorrent {
}
dispatchError (e) {
if (typeof ErrorEvent !== 'undefined' && e instanceof ErrorEvent) return this.dispatchError(e.error)
if (typeof PromiseRejectionEvent !== 'undefined' && e instanceof PromiseRejectionEvent) return this.dispatchError(e.reason)
for (const exclude of TorrentClient.excludedErrorMessages) {
if (e.message?.startsWith(exclude)) return
if (typeof Event !== 'undefined' && e instanceof Event) {
if (e.error) return this.dispatchError(e.error)
if (e.message) return this.dispatchError(e.message)
if (e.reason) return this.dispatchError(e.reason)
return this.dispatchError(JSON.stringify(e))
}
this.dispatch('error', JSON.stringify(e?.message || e))
if (typeof Error !== 'undefined' && e instanceof Error) {
if (e.message) return this.dispatchError(e.message)
if (e.cause) return this.dispatchError(e.cause)
if (e.reason) return this.dispatchError(e.reason)
if (e.name) return this.dispatchError(e.name)
return this.dispatchError(JSON.stringify(e))
}
if (typeof e !== 'string') return this.dispatchError(JSON.stringify(e))
for (const exclude of TorrentClient.excludedErrorMessages) {
if (e.startsWith(exclude)) return
}
console.error(e)
this.dispatch('error', e)
}
async addTorrent (data, skipVerify = false) {
@ -217,7 +236,7 @@ export default class TorrentClient extends WebTorrent {
if (existing.ready) this.handleTorrent(existing)
return
}
localStorage.setItem('lastFinished', false)
localStorage.setItem('lastFinished', 'false')
if (this.torrents.length) await this.remove(this.torrents[0])
const torrent = await this.add(data, {
private: this.settings.torrentPeX,
@ -228,7 +247,7 @@ export default class TorrentClient extends WebTorrent {
})
torrent.once('done', () => {
if (SUPPORTS.torrentPersist && this.settings.torrentPath) localStorage.setItem('lastFinished', true)
if (SUPPORTS.torrentPersist && this.settings.torrentPath) localStorage.setItem('lastFinished', 'true')
})
}

View file

@ -1,6 +1,6 @@
{
"name": "Miru",
"version": "5.1.0",
"version": "5.1.1",
"private": true,
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
"description": "Stream anime torrents, real-time with no waiting for downloads.",
@ -73,6 +73,8 @@
"singleArchFiles": "node_modules/+(register-scheme|utp-native|fs-native-extensions)/**",
"category": "public.app-category.video",
"icon": "buildResources/icon.icns",
"hardenedRuntime": true,
"entitlements": "buildResources/entitlements.mac.plist",
"target": [
{
"arch": "universal",

View file

@ -30,7 +30,7 @@
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.2",
"webtorrent": "^2.3.2"
"webtorrent": "^2.4.1"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240222.0",

View file

@ -51,8 +51,8 @@ importers:
specifier: ^5.0.2
version: 5.0.2(webpack-cli@5.1.4)(webpack@5.91.0)
webtorrent:
specifier: ^2.3.2
version: 2.3.2
specifier: ^2.4.1
version: 2.4.1
devDependencies:
'@cloudflare/workers-types':
specifier: ^4.20240222.0
@ -436,7 +436,7 @@ packages:
resolution: {integrity: sha512-aL+bFMIkpR0cmmj5Zgy0LMKEpgy43/hw5zadEArgmAMWWlKc5buwFvFT9G/o/YJkvXAJm5q3iuTuLaiaXW39sg==}
engines: {node: '>= 10.0.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
fs-extra: 9.1.0
promise-retry: 2.0.1
transitivePeerDependencies:
@ -460,7 +460,7 @@ packages:
hasBin: true
dependencies:
compare-version: 0.1.2
debug: 4.3.4
debug: 4.3.5
fs-extra: 10.1.0
isbinaryfile: 4.0.10
minimist: 1.2.8
@ -475,7 +475,7 @@ packages:
dependencies:
'@electron/asar': 3.2.10
'@malept/cross-spawn-promise': 1.1.1
debug: 4.3.4
debug: 4.3.5
dir-compare: 3.3.0
fs-extra: 9.1.0
minimatch: 3.1.2
@ -779,7 +779,7 @@ packages:
resolution: {integrity: sha512-0JZ1Zkp3wURnv8oq6Qt7fMPo5MpjbLoUoa9Bu2Q4PJuSDWM8H8gwF3dQO7VTeUj3/0o1IB1wGkFWZZYgUXZMUg==}
engines: {node: '>=16.0.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
tslib: 2.6.2
transitivePeerDependencies:
- supports-color
@ -789,7 +789,7 @@ packages:
engines: {node: '>=16.0.0'}
dependencies:
'@types/fs-extra': 8.1.5
debug: 4.3.4
debug: 4.3.5
fs-extra: 9.1.0
tslib: 2.6.2
transitivePeerDependencies:
@ -799,7 +799,7 @@ packages:
resolution: {integrity: sha512-vCl7sl6JjBHFw99CuAqHljYJpcE88YaH2ZW4ELiC/Zwxl5tiwn4kbdP/gxi2OT3MQb1vOtgAmSNRtusvgxI8ww==}
engines: {node: '>=16.0.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
tslib: 2.6.2
transitivePeerDependencies:
- supports-color
@ -810,7 +810,7 @@ packages:
dependencies:
'@ionic/utils-object': 2.1.6
'@ionic/utils-terminal': 2.3.4
debug: 4.3.4
debug: 4.3.5
signal-exit: 3.0.7
tree-kill: 1.2.2
tslib: 2.6.2
@ -821,7 +821,7 @@ packages:
resolution: {integrity: sha512-4+Kitey1lTA1yGtnigeYNhV/0tggI3lWBMjC7tBs1K9GXa/q7q4CtOISppdh8QgtOhrhAXS2Igp8rbko/Cj+lA==}
engines: {node: '>=16.0.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
tslib: 2.6.2
transitivePeerDependencies:
- supports-color
@ -846,7 +846,7 @@ packages:
engines: {node: '>=16.0.0'}
dependencies:
'@types/slice-ansi': 4.0.0
debug: 4.3.4
debug: 4.3.5
signal-exit: 3.0.7
slice-ansi: 4.0.0
string-width: 4.2.3
@ -964,7 +964,7 @@ packages:
resolution: {integrity: sha512-9QOtNffcOF/c1seMCDnjckb3R9WHcG34tky+FHpNKKCW0wc/scYLwMtO+ptyGUfMW0/b/n4qRiALlaFHc9Oj7Q==}
engines: {node: '>= 10.0.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
fs-extra: 9.1.0
lodash: 4.17.21
tmp-promise: 3.0.3
@ -1149,7 +1149,7 @@ packages:
dependencies:
chrome-dgram: 3.0.6
cross-fetch-ponyfill: 1.0.3
debug: 4.3.4
debug: 4.3.5
default-gateway: 6.0.3
unordered-array-remove: 1.0.2
xml2js: 0.6.2
@ -1268,7 +1268,7 @@ packages:
/@thaunknown/simple-peer@10.0.7:
resolution: {integrity: sha512-b4oPNaJEWk9UT/ADV8IFWcAyow+gOPLa73SptuOqm6IdMDr4zlsqGsdl4LQmvgMKMgWAOHdVViw/RYF5qYvkCg==}
dependencies:
debug: 4.3.4
debug: 4.3.5
err-code: 3.0.1
streamx: 2.16.1
uint8-util: 2.2.5
@ -1280,7 +1280,7 @@ packages:
/@thaunknown/simple-peer@9.12.1:
resolution: {integrity: sha512-IS5BXvXx7cvBAzaxqotJf4s4rJCPk5JABLK6Gbnn7oAmWVcH4hYABabBBrvvJtv/xyUqR4v/H3LalnGRJJfEog==}
dependencies:
debug: 4.3.4
debug: 4.3.5
err-code: 3.0.1
get-browser-rtc: 1.1.0
queue-microtask: 1.2.3
@ -1293,7 +1293,7 @@ packages:
/@thaunknown/simple-websocket@9.1.1(bufferutil@4.0.8)(utf-8-validate@5.0.10):
resolution: {integrity: sha512-vzQloFWRodRZqZhpxMpBljFtISesY8TihA8T5uKwCYdj2I1ImMhE/gAeTCPsCGOtxJfGKu3hw/is6MXauWLjOg==}
dependencies:
debug: 4.3.4
debug: 4.3.5
queue-microtask: 1.2.3
streamx: 2.16.1
uint8-util: 2.2.5
@ -1307,7 +1307,7 @@ packages:
/@thaunknown/simple-websocket@9.1.1(bufferutil@4.0.8)(utf-8-validate@6.0.4):
resolution: {integrity: sha512-vzQloFWRodRZqZhpxMpBljFtISesY8TihA8T5uKwCYdj2I1ImMhE/gAeTCPsCGOtxJfGKu3hw/is6MXauWLjOg==}
dependencies:
debug: 4.3.4
debug: 4.3.5
queue-microtask: 1.2.3
streamx: 2.16.1
uint8-util: 2.2.5
@ -1885,7 +1885,7 @@ packages:
resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==}
engines: {node: '>= 6.0.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
transitivePeerDependencies:
- supports-color
dev: true
@ -2320,12 +2320,12 @@ packages:
engines: {node: '>=8'}
dev: false
/bittorrent-dht@11.0.5:
resolution: {integrity: sha512-R09D6uNaziRqsc+B/j5QzkjceTak+wH9vcNLnkmt8A52EWF9lQwBP0vvCKgSA3AJOYYl+41n3osA2KYYn/z5uQ==}
/bittorrent-dht@11.0.6:
resolution: {integrity: sha512-iDScIyLDKuuXOSIlPIxnvzH3llqatVkugjn3CSPPpjcHO+4dyahHiiPRpzR39k4l9qW79YAbI/AzSjNWoLchHQ==}
engines: {node: '>=12.20.0'}
dependencies:
bencode: 4.0.0
debug: 4.3.4
debug: 4.3.5
k-bucket: 5.1.0
k-rpc: 5.1.0
last-one-wins: 1.0.4
@ -2341,7 +2341,7 @@ packages:
engines: {node: '>=12.20.0'}
dependencies:
chrome-dgram: 3.0.6
debug: 4.3.4
debug: 4.3.5
transitivePeerDependencies:
- supports-color
dev: false
@ -2350,13 +2350,13 @@ packages:
resolution: {integrity: sha512-VyLcUjVMEOdSpHaCG/7odvCdLbAB1y3l9A2V6WIje24uV7FkJPrQrH/RrlFmKxP89pFVDEnE+YlHaFujlFIZsg==}
dev: false
/bittorrent-protocol@4.1.11:
resolution: {integrity: sha512-8ehCNnnRpxB6wrqDzYdLY6Bx0k1ZcXwHmxfVsU9xljolgfd4jhUq9gKcbnnUj4yR8I5/qHJ5fYVoGIfrmUlAAQ==}
/bittorrent-protocol@4.1.12:
resolution: {integrity: sha512-peyUDP5NQaiPSau24jCpPhLfDFCCK1DUE0N5xlJSPVIkgQmsVLi62N/Lm++pUNrBenfnhf6WKQo0nyN6x5dufQ==}
engines: {node: '>=12.20.0'}
dependencies:
bencode: 4.0.0
bitfield: 4.2.0
debug: 4.3.4
debug: 4.3.5
rc4: 0.1.5
streamx: 2.16.1
throughput: 1.0.1
@ -2378,7 +2378,7 @@ packages:
chrome-dgram: 3.0.6
clone: 2.1.2
compact2string: 1.4.1
debug: 4.3.4
debug: 4.3.5
ip: 1.1.9
lru: 3.1.0
minimist: 1.2.8
@ -2413,7 +2413,7 @@ packages:
clone: 2.1.2
compact2string: 1.4.1
cross-fetch-ponyfill: 1.0.3
debug: 4.3.4
debug: 4.3.5
ip: 2.0.1
lru: 3.1.0
minimist: 1.2.8
@ -3458,6 +3458,17 @@ packages:
dependencies:
ms: 2.1.2
/debug@4.3.5:
resolution: {integrity: sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.2
/decamelize-keys@1.1.1:
resolution: {integrity: sha512-WiPxgEirIV0/eIOMcnFBA3/IJZAZqKnwAwWyvvdi4lsr1WCN22nhdf/3db3DoZcUjTV2SqfzIwNyp6y2xs3nmg==}
engines: {node: '>=0.10.0'}
@ -5221,7 +5232,7 @@ packages:
dependencies:
'@tootallnate/once': 2.0.0
agent-base: 6.0.2
debug: 4.3.4
debug: 4.3.5
transitivePeerDependencies:
- supports-color
dev: true
@ -5276,7 +5287,7 @@ packages:
engines: {node: '>= 6'}
dependencies:
agent-base: 6.0.2
debug: 4.3.4
debug: 4.3.5
transitivePeerDependencies:
- supports-color
dev: true
@ -6046,11 +6057,11 @@ packages:
inherits: 2.0.4
dev: false
/lt_donthave@2.0.0:
resolution: {integrity: sha512-qrNtq9faD5ycTM8Of7OUqPHPMv0H8NONf+dTAxUsAr0bAgPnD56BBhhBlskJVNL4WO+Dl/qmqWHF9eQb7+2lNA==}
/lt_donthave@2.0.1:
resolution: {integrity: sha512-GhiKG7CGTXzOQq56tIx40Ae26EbrgBq1owuuPqgCTaJDQYO1qW5G+YGaurOLx7s+Aaeta8MputrVFDr0kuiogg==}
engines: {node: '>=12.20.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
unordered-array-remove: 1.0.2
transitivePeerDependencies:
- supports-color
@ -7174,6 +7185,10 @@ packages:
/q@1.5.1:
resolution: {integrity: sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==}
engines: {node: '>=0.6.0', teleport: '>=0.2.0'}
deprecated: |-
You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.
(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
dev: true
/qs@6.11.0:
@ -8035,7 +8050,7 @@ packages:
/spdy-transport@3.0.0:
resolution: {integrity: sha512-hsLVFE5SjA6TCisWeJXFKniGGOpBgMLmerfO2aCyCU5s7nJ/rpAepqmFifv/GCbSbueEeAJJnmSQ2rKC/g8Fcw==}
dependencies:
debug: 4.3.4
debug: 4.3.5
detect-node: 2.1.0
hpack.js: 2.1.6
obuf: 1.1.2
@ -8247,7 +8262,7 @@ packages:
resolution: {integrity: sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==}
engines: {node: '>= 8.0'}
dependencies:
debug: 4.3.4
debug: 4.3.5
transitivePeerDependencies:
- supports-color
dev: true
@ -8632,14 +8647,14 @@ packages:
resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
engines: {node: '>=0.6'}
/torrent-discovery@11.0.4:
resolution: {integrity: sha512-cV8jWLkdXeYBRvy5Z7j9g85rN4+IBMejN25aV7GA9ANpTxF5BMU5CH8XZZb9n2+8RR4ihcgqDbpGoa6CDfoUsg==}
/torrent-discovery@11.0.6:
resolution: {integrity: sha512-9gnsBZLuOzbWlTIv0lx3pjmZ2Bj4WZfY06iO9AXKiNxA7/k508CWIE80PojYsgsR9SyjDkIVfnHLyJOgnDycvQ==}
engines: {node: '>=16.0.0'}
dependencies:
bittorrent-dht: 11.0.5
bittorrent-dht: 11.0.6
bittorrent-lsd: 2.0.0
bittorrent-tracker: 11.1.0
debug: 4.3.4
debug: 4.3.5
run-parallel: 1.2.0
transitivePeerDependencies:
- supports-color
@ -8935,7 +8950,7 @@ packages:
dependencies:
bencode: 4.0.0
bitfield: 4.2.0
debug: 4.3.4
debug: 4.3.5
uint8-util: 2.2.5
transitivePeerDependencies:
- supports-color
@ -9295,8 +9310,8 @@ packages:
resolution: {integrity: sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==}
engines: {node: '>=0.8.0'}
/webtorrent@2.3.2:
resolution: {integrity: sha512-t/NhKQ4pn20PEwLdrsjNfQu24Jd7cpDr4hfYRIFMW8iWIjeQJnTf/uGvqAraAoRYMf0hkEbk9KyoVJrC5iT2hQ==}
/webtorrent@2.4.1:
resolution: {integrity: sha512-9/WTMFaAAbfopNQiGK5rD7ZJJTdPwOrl/T6izTWVEk56+cJdtZBz9FelMnwnS4Q7rqFKoEYuonzi+ig0nXjYsA==}
engines: {node: '>=16'}
dependencies:
'@silentbot1/nat-api': 0.4.7
@ -9304,21 +9319,21 @@ packages:
'@webtorrent/http-node': 1.3.0
addr-to-ip-port: 2.0.0
bitfield: 4.2.0
bittorrent-dht: 11.0.5
bittorrent-protocol: 4.1.11
bittorrent-dht: 11.0.6
bittorrent-protocol: 4.1.12
cache-chunk-store: 3.2.2
chunk-store-iterator: 1.0.3
cpus: 1.0.3
create-torrent: 6.0.17
cross-fetch-ponyfill: 1.0.3
debug: 4.3.4
debug: 4.3.5
escape-html: 1.0.3
fs-chunk-store: 4.1.0
hybrid-chunk-store: 1.2.4
immediate-chunk-store: 2.2.0
join-async-iterator: 1.1.1
load-ip-set: 3.0.1
lt_donthave: 2.0.0
lt_donthave: 2.0.1
memory-chunk-store: 1.3.5
mime: 3.0.0
once: 1.4.0
@ -9332,7 +9347,7 @@ packages:
speed-limiter: 1.0.2
streamx: 2.16.1
throughput: 1.0.1
torrent-discovery: 11.0.4
torrent-discovery: 11.0.6
torrent-piece: 3.0.0
uint8-util: 2.2.5
unordered-array-remove: 1.0.2