Skip to content

Commit

Permalink
Fix: root user password change #93, Change: link to series filter on …
Browse files Browse the repository at this point in the history
…ab page #90, Add: basic mobi and azw3 ereader support
  • Loading branch information
advplyr committed Oct 11, 2021
1 parent 120c706 commit 9715c53
Show file tree
Hide file tree
Showing 10 changed files with 876 additions and 15 deletions.
405 changes: 405 additions & 0 deletions client/assets/mobi.js

Large diffs are not rendered by default.

52 changes: 47 additions & 5 deletions client/components/app/Reader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
</select>
</div> -->
<div class="absolute top-4 left-4 font-book">
<h1 class="text-2xl mb-1">{{ title }}</h1>

<p v-if="author">by {{ author }}</p>
<h1 class="text-2xl mb-1">{{ title || abTitle }}</h1>
<p v-if="author || abAuthor">by {{ author || abAuthor }}</p>
</div>
<div v-if="!epubEbook && mobiEbook" class="absolute top-4 left-0 w-full flex justify-center">
<p class="text-error font-semibold">Warning: Reading mobi & azw3 files is in the very early stages</p>
</div>
<div class="h-full flex items-center">

<div v-if="epubEbook" class="h-full flex items-center">
<div style="width: 100px; max-width: 100px" class="h-full flex items-center overflow-x-hidden">
<span v-show="hasPrev" class="material-icons text-black text-opacity-30 hover:text-opacity-80 cursor-pointer text-8xl" @mousedown.prevent @click="pageLeft">chevron_left</span>
</div>
Expand All @@ -28,11 +31,17 @@
<span v-show="hasNext" class="material-icons text-black text-opacity-30 hover:text-opacity-80 cursor-pointer text-8xl" @mousedown.prevent @click="pageRight">chevron_right</span>
</div>
</div>
<div v-else class="h-full flex items-center justify-center">
<div class="w-full max-w-4xl overflow-y-auto border border-black border-opacity-10 p-4" style="max-height: 80vh">
<div id="viewer" />
</div>
</div>
</div>
</template>

<script>
import ePub from 'epubjs'
import mobijs from '@/assets/mobi.js'
export default {
data() {
Expand Down Expand Up @@ -65,6 +74,12 @@ export default {
this.$store.commit('setShowEReader', val)
}
},
abTitle() {
return this.selectedAudiobook.book.title
},
abAuthor() {
return this.selectedAudiobook.book.author
},
selectedAudiobook() {
return this.$store.state.selectedAudiobook
},
Expand All @@ -83,6 +98,16 @@ export default {
epubPath() {
return this.epubEbook ? this.epubEbook.path : null
},
mobiEbook() {
return this.ebooks.find((eb) => eb.ext === '.mobi' || eb.ext === '.azw3')
},
mobiPath() {
return this.mobiEbook ? this.mobiEbook.path : null
},
mobiUrl() {
if (!this.mobiPath) return null
return `/ebook/${this.libraryId}/${this.folderId}/${this.mobiPath}`
},
url() {
if (!this.epubPath) return null
return `/ebook/${this.libraryId}/${this.folderId}/${this.epubPath}`
Expand Down Expand Up @@ -134,7 +159,24 @@ export default {
init() {
this.registerListeners()
console.log('epub', this.url, this.epubEbook, this.ebooks)
if (this.epubEbook) {
this.initEpub()
} else if (this.mobiEbook) {
this.initMobi()
}
},
async initMobi() {
var buff = await this.$axios.$get(this.mobiUrl, {
responseType: 'blob'
})
var reader = new FileReader()
reader.onload = function (event) {
var file_content = event.target.result
new mobijs(file_content).render_to('viewer')
}
reader.readAsArrayBuffer(buff)
},
initEpub() {
// var book = ePub(this.url, {
// requestHeaders: {
// Authorization: `Bearer ${this.userToken}`
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "audiobookshelf-client",
"version": "1.4.5",
"version": "1.4.6",
"description": "Audiobook manager and player",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion client/pages/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="flex items-center py-2">
<p v-if="isRoot" class="text-error py-2 text-xs">* Root user is the only user that can have an empty password</p>
<div class="flex-grow" />
<ui-btn v-show="password && newPassword && confirmPassword" type="submit" :loading="changingPassword" color="success">Submit</ui-btn>
<ui-btn v-show="(password && newPassword && confirmPassword) || isRoot" type="submit" :loading="changingPassword" color="success">Submit</ui-btn>
</div>
</form>
</div>
Expand Down
15 changes: 11 additions & 4 deletions client/pages/audiobook/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
by <nuxt-link v-if="author" :to="`/library/${libraryId}/bookshelf?filter=authors.${$encode(author)}`" class="hover:underline">{{ author }}</nuxt-link
><span v-else>Unknown</span>
</p>

<h3 v-if="series" class="font-sans text-gray-300 text-lg leading-7 mb-4">{{ seriesText }}</h3>
<nuxt-link v-if="series" :to="`/library/${libraryId}/bookshelf?filter=series.${$encode(series)}`" class="hover:underline font-sans text-gray-300 text-lg leading-7 mb-4"> {{ seriesText }}</nuxt-link>

<!-- <div class="w-min">
<ui-tooltip :text="authorTooltipText" direction="bottom">
Expand Down Expand Up @@ -105,7 +104,7 @@
{{ isMissing ? 'Missing' : 'Incomplete' }}
</ui-btn>

<ui-btn v-if="showExperimentalFeatures && epubEbook" color="info" :padding-x="4" small class="flex items-center h-9 mr-2" @click="openEbook">
<ui-btn v-if="showExperimentalFeatures && (epubEbook || mobiEbook)" color="info" :padding-x="4" small class="flex items-center h-9 mr-2" @click="openEbook">
<span class="material-icons -ml-2 pr-2 text-white">auto_stories</span>
Read
</ui-btn>
Expand Down Expand Up @@ -329,7 +328,10 @@ export default {
return !this.tracks.length && this.ebooks.length && !this.showExperimentalFeatures
},
epubEbook() {
return this.audiobook.ebooks.find((eb) => eb.ext === '.epub')
return this.ebooks.find((eb) => eb.ext === '.epub')
},
mobiEbook() {
return this.ebooks.find((eb) => eb.ext === '.mobi' || eb.ext === '.azw3')
},
userToken() {
return this.$store.getters['user/getToken']
Expand Down Expand Up @@ -455,6 +457,11 @@ export default {
},
mounted() {
this.$store.commit('audiobooks/addListener', { id: 'audiobook', audiobookId: this.audiobookId, meth: this.audiobookUpdated })
// If a library has not yet been loaded, use this audiobooks library id as the current
if (!this.$store.state.audiobooks.loadedLibraryId && this.libraryId) {
this.$store.commit('libraries/setCurrentLibrary', this.libraryId)
}
},
beforeDestroy() {
this.$store.commit('audiobooks/removeListener', 'audiobook')
Expand Down
1 change: 0 additions & 1 deletion client/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const mutations = {
state.showEditModal = val
},
showEReader(state, audiobook) {
console.log('Show EReader', audiobook)
state.selectedAudiobook = audiobook
state.showEReader = true
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "audiobookshelf",
"version": "1.4.5",
"version": "1.4.6",
"description": "Self-hosted audiobook server for managing and playing audiobooks",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion server/objects/Audiobook.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class Audiobook {
return this.otherFiles.find(file => file.ext === '.epub')
}

get hasMobi() {
return this.otherFiles.find(file => file.ext === '.mobi' || file.ext === '.azw3')
}

get hasMissingIno() {
return !this.ino || this._audioFiles.find(abf => !abf.ino) || this._otherFiles.find(f => !f.ino) || this._tracks.find(t => !t.ino)
}
Expand Down Expand Up @@ -202,7 +206,7 @@ class Audiobook {
hasInvalidParts: this.invalidParts ? this.invalidParts.length : 0,
// numEbooks: this.ebooks.length,
ebooks: this.ebooks.map(ebook => ebook.toJSON()),
numEbooks: this.hasEpub ? 1 : 0, // Only supporting epubs in the reader currently
numEbooks: (this.hasEpub || this.hasMobi) ? 1 : 0, // Only supporting epubs in the reader currently
numTracks: this.tracks.length,
chapters: this.chapters || [],
isMissing: !!this.isMissing,
Expand Down
2 changes: 1 addition & 1 deletion server/utils/globals.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const globals = {
SupportedImageTypes: ['png', 'jpg', 'jpeg', 'webp'],
SupportedAudioTypes: ['m4b', 'mp3', 'm4a', 'flac', 'opus', 'mp4'],
SupportedEbookTypes: ['epub', 'pdf', 'mobi']
SupportedEbookTypes: ['epub', 'pdf', 'mobi', 'azw3']
}

module.exports = globals
Loading

0 comments on commit 9715c53

Please sign in to comment.