Skip to content

Commit

Permalink
feat: add inventaireio metadata plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bayang committed Nov 5, 2024
1 parent d251af1 commit 1fdbf37
Show file tree
Hide file tree
Showing 31 changed files with 886 additions and 46 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ dependencies {
// implementation("com.unboundid:unboundid-ldapsdk:6.0.5")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")

implementation("org.apache.httpcomponents.client5:httpclient5")

implementation("com.github.ben-manes.caffeine:caffeine")

implementation("com.fasterxml.staxmate:staxmate:2.4.1")
Expand Down
36 changes: 36 additions & 0 deletions src/jelu-ui/src/components/AddBook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const form = reactive({
amazonId: "",
goodreadsId: "",
librarythingId: "",
isfdbId: "",
openlibraryId: "",
noosfereId: "",
inventaireId: "",
language: ""
});
const eventType = ref(null);
Expand Down Expand Up @@ -210,6 +214,10 @@ const fillBook = (formdata: any, publishedDate: Date | null): UserBook => {
amazonId: formdata.amazonId,
goodreadsId: formdata.goodreadsId,
librarythingId: formdata.librarythingId,
isfdbId: formdata.isfdbId,
openlibraryId: formdata.openlibraryId,
noosfereId: formdata.noosfereId,
inventaireId: formdata.inventaireId,
language: formdata.language,
authors: [],
translators: [],
Expand Down Expand Up @@ -249,6 +257,10 @@ const clearForm = () => {
form.googleId = ""
form.goodreadsId = ""
form.librarythingId = ""
form.isfdbId = ""
form.openlibraryId = ""
form.noosfereId = ""
form.inventaireId = ""
form.percentRead = null
form.currentPageNumber = null
};
Expand Down Expand Up @@ -701,6 +713,30 @@ let displayDatepicker = computed(() => {
:placeholder="t('book.librarything_id')"
class="input focus:input-accent"
/>
<o-input
v-model="form.isfdbId"
name="isfdbId"
:placeholder="t('book.isfdb_id')"
class="input focus:input-accent"
/>
<o-input
v-model="form.openlibraryId"
name="openlibraryId"
:placeholder="t('book.openlibrary_id')"
class="input focus:input-accent"
/>
<o-input
v-model="form.noosfereId"
name="noosfereId"
:placeholder="t('book.noosfere_id')"
class="input focus:input-accent"
/>
<o-input
v-model="form.inventaireId"
name="inventaireId"
:placeholder="t('book.inventaire_id')"
class="input focus:input-accent"
/>
</o-field>
</div>
<div class="field mb-3">
Expand Down
61 changes: 60 additions & 1 deletion src/jelu-ui/src/components/BookDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ const sortedEvents = computed(() => {
const hasExternalLink = computed(() => book.value?.book.amazonId != null
|| book.value?.book.goodreadsId != null
|| book.value?.book.googleId != null
|| book.value?.book.librarythingId != null)
|| book.value?.book.librarythingId != null
|| book.value?.book.openlibraryId != null
|| book.value?.book.isfdbId != null
|| book.value?.book.noosfereId != null
|| book.value?.book.inventaireId != null)
function modalClosed() {
console.log("modal closed")
Expand Down Expand Up @@ -516,6 +520,16 @@ const formatSeries = async (series: Series) => {
const timestamp = () => new Date().toISOString()
let currentTimestamp = timestamp()
const getIsbn = (): string|null => {
if (book.value?.book.isbn13 && book.value.book.isbn13.length > 0) {
return book.value.book.isbn13.replaceAll("-", "")
}
if (book.value?.book.isbn10 && book.value.book.isbn10.length > 0) {
return book.value.book.isbn10.replaceAll("-", "")
}
return null
}
getBook()
</script>
Expand Down Expand Up @@ -875,6 +889,51 @@ getBook()
target="_blank"
>librarything</a>
</span>
<span
v-if="book?.book.isfdbId"
class="badge badge-warning hover:font-bold"
>
<a
:href="'https://www.isfdb.org/cgi-bin/title.cgi?' + book.book.isfdbId"
target="_blank"
>ISFDB</a>
</span>
<span
v-if="book?.book.openlibraryId"
class="badge badge-warning hover:font-bold"
>
<a
:href="`https://openlibrary.org/works/${book.book.openlibraryId}?mode=all`"
target="_blank"
>Openlibrary</a>
</span>
<span
v-if="book?.book.noosfereId"
class="badge badge-warning hover:font-bold"
>
<a
:href="'https://www.noosfere.org/livres/EditionsLivre.asp?numitem=' + book.book.noosfereId"
target="_blank"
>Noosfere</a>
</span>
<span
v-if="getIsbn() != null"
class="badge badge-warning hover:font-bold"
>
<a
:href="'https://inventaire.io/entity/isbn:' + getIsbn()"
target="_blank"
>inventaire</a>
</span>
<span
v-else-if="book?.book.inventaireId"
class="badge badge-warning hover:font-bold"
>
<a
:href="'https://inventaire.io/entity/inv:' + book.book.inventaireId"
target="_blank"
>inventaire</a>
</span>
</div>
<div
v-if="book?.personalNotes"
Expand Down
24 changes: 24 additions & 0 deletions src/jelu-ui/src/components/MetadataDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ defineProps<{
>
<span class="font-semibold">{{ t('book.amazon_id') }} : </span>{{ metadata.amazonId }}
</p>
<p
v-if="metadata?.isfdbId"
class="mb-2"
>
<span class="font-semibold">{{ t('book.isfdb_id') }} : </span>{{ metadata.isfdbId }}
</p>
<p
v-if="metadata?.openlibraryId"
class="mb-2"
>
<span class="font-semibold">{{ t('book.openlibrary_id') }} : </span>{{ metadata.openlibraryId }}
</p>
<p
v-if="metadata?.noosfereId"
class="mb-2"
>
<span class="font-semibold">{{ t('book.noosfere_id') }} : </span>{{ metadata.noosfereId }}
</p>
<p
v-if="metadata?.inventaireId"
class="mb-2"
>
<span class="font-semibold">{{ t('book.inventaire_id') }} : </span>{{ metadata.inventaireId }}
</p>
<p
v-if="metadata?.tags != null && metadata?.tags?.length > 0"
>
Expand Down
11 changes: 8 additions & 3 deletions src/jelu-ui/src/components/MetadataPluginsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function checkMove(evt: any){
>
{{ t('metadata.reorder_plugins') }}
</h1>
<p>{{ t('metadata.description') }}</p>
<p class="text-justify">
{{ t('metadata.description') }}
</p>
<div class="flex flex-wrap place-content-center my-3">
<draggable
v-model="plugins"
Expand Down Expand Up @@ -107,7 +109,7 @@ function checkMove(evt: any){
</div>
</template>
</draggable>
<div class="my-3">
<div class="m-3">
<button
class="btn btn-primary mr-2 uppercase"
:disabled="progress"
Expand All @@ -120,7 +122,7 @@ function checkMove(evt: any){
<span class="icon">
<i class="mdi mdi-pencil mdi-18px" />
</span>
<span>{{ t('labels.submit') }}</span>
<span>{{ t('labels.apply') }}</span>
</button>
<button
class="btn btn-secondary mr-2 uppercase"
Expand All @@ -137,6 +139,9 @@ function checkMove(evt: any){
<span>{{ t('labels.discard') }}</span>
</button>
</div>
<p class="mt-3 text-sm">
{{ t('metadata.note') }}
</p>
</div>
</div>
</section>
Expand Down
12 changes: 9 additions & 3 deletions src/jelu-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
"avg_rating" : "average rating : {rating}",
"add_quote" : "add book quote",
"description" : "description",
"user_rating" : "my rating : {rating}"
"user_rating" : "my rating : {rating}",
"apply" : "apply"
},
"settings" : {
"pick_language" : "Pick your language",
Expand Down Expand Up @@ -202,6 +203,10 @@
"goodreads_id" : "Goodreads Id",
"amazon_id" : "Amazon Id",
"librarything_id" : "Librarything Id",
"isfdb_id" : "ISFDB Id",
"openlibrary_id" : "Openlibrary Id",
"noosfere_id" : "Noosfere Id",
"inventaire_id" : "inventaire id",
"publisher" : "publisher",
"published_date" : "published date",
"page_count" : "page count",
Expand Down Expand Up @@ -337,8 +342,9 @@
},
"metadata" : {
"reorder_plugins" : "reorder plugins",
"description" : "Plugins will be called from top to bottom, disabled plugins will not be used",
"default_priority" : "default priority"
"description" : "Plugins will be called from top to bottom, disabled plugins will not be used.",
"default_priority" : "default priority",
"note" : "This change is only temporary, if you want to permanently reorder the plugins you have to edit the config."
},
"book_quotes" : {
"edit_quote" : "Edit book quote",
Expand Down
4 changes: 4 additions & 0 deletions src/jelu-ui/src/model/Book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface Book {
amazonId?: string,
goodreadsId?: string,
librarythingId?: string,
isfdbId?: string,
openlibraryId?: string,
noosfereId?: string,
inventaireId?: string,
language?: string,
userBookId?: string,
userbook?: UserBook,
Expand Down
6 changes: 5 additions & 1 deletion src/jelu-ui/src/model/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export interface Metadata {
googleId?: string,
amazonId?: string,
goodreadsId?: string,
}
isfdbId?: string,
openlibraryId?: string,
noosfereId?: string,
inventaireId?: string,
}
6 changes: 6 additions & 0 deletions src/main/kotlin/io/github/bayang/jelu/config/GlobalConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.http.codec.ClientCodecConfigurer
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.web.client.RestClient
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.reactive.function.client.ExchangeStrategies
Expand All @@ -31,6 +32,11 @@ class GlobalConfig {
).build()
}

@Bean("springRestClient")
fun springRestClient(): RestClient {
return RestClient.create()
}

@Bean("passwordEncoder")
fun passwordEncoder(): PasswordEncoder = BCryptPasswordEncoder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class JeluProperties(
var isEnabled: Boolean = false,
var apiKey: String?,
var order: Int = -1000,
var config: String? = null,
)

data class Database(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MetadataController(
@RequestParam(name = "isbn", required = false) isbn: String?,
@RequestParam(name = "title", required = false) title: String?,
@RequestParam(name = "authors", required = false) authors: String?,
): Mono<MetadataDto> =
): MetadataDto =
if (pluginInfoHolder.plugins().isEmpty()) {
throw JeluException("Automatic fetching of metadata is disabled, install calibre or configure a metadata plugin")
} else {
Expand Down Expand Up @@ -71,7 +71,7 @@ class MetadataController(
fun fetchMetadata(
@RequestBody @Valid
metadataRequestDto: MetadataRequestDto,
): Mono<MetadataDto> {
): MetadataDto {
if (pluginInfoHolder.plugins().isEmpty()) {
throw JeluException("Automatic fetching of metadata is disabled, install calibre or configure a metadata plugin")
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/io/github/bayang/jelu/dao/BookRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,18 @@ class BookRepository(
book.librarythingId?.let {
updated.librarythingId = book.librarythingId.trim()
}
book.isfdbId?.let {
updated.isfdbId = book.isfdbId.trim()
}
book.openlibraryId?.let {
updated.openlibraryId = book.openlibraryId.trim()
}
book.noosfereId?.let {
updated.noosfereId = book.noosfereId
}
book.inventaireId?.let {
updated.inventaireId = book.inventaireId
}
book.language?.let {
updated.language = book.language.trim()
}
Expand Down Expand Up @@ -929,6 +941,10 @@ class BookRepository(
this.goodreadsId = cleanString(book.goodreadsId)
this.googleId = cleanString(book.googleId)
this.librarythingId = cleanString(book.librarythingId)
this.isfdbId = cleanString(book.isfdbId)
this.openlibraryId = cleanString(book.openlibraryId)
this.noosfereId = cleanString(book.noosfereId)
this.inventaireId = cleanString(book.inventaireId)
this.language = cleanString(book.language)
}
book.series?.forEach {
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/io/github/bayang/jelu/dao/BookTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ object BookTable : UUIDTable("book") {
val goodreadsId: Column<String?> = varchar("goodreads_id", 30).nullable()
val amazonId: Column<String?> = varchar("amazon_id", 30).nullable()
val librarythingId: Column<String?> = varchar("librarything_id", 30).nullable()
val isfdbId: Column<String?> = varchar("isfdb_id", length = 30).nullable()
val openlibraryId: Column<String?> = varchar("openlibrary_id", 30).nullable()
val noosfereId: Column<String?> = varchar("noosfere_id", 128).nullable()
val inventaireId: Column<String?> = varchar("inventaire_id", 128).nullable()
val language: Column<String?> = varchar("language", 30).nullable()
}
class Book(id: EntityID<UUID>) : UUIDEntity(id) {
Expand All @@ -52,6 +56,10 @@ class Book(id: EntityID<UUID>) : UUIDEntity(id) {
var amazonId by BookTable.amazonId
var goodreadsId by BookTable.goodreadsId
var librarythingId by BookTable.librarythingId
var isfdbId by BookTable.isfdbId
var openlibraryId by BookTable.openlibraryId
var noosfereId by BookTable.noosfereId
var inventaireId by BookTable.inventaireId
val userBooks by UserBook referrersOn UserBookTable.book
var userBookId: UUID? = null
var userBook: UserBook? = null
Expand All @@ -75,6 +83,10 @@ class Book(id: EntityID<UUID>) : UUIDEntity(id) {
googleId = this.googleId,
amazonId = this.amazonId,
librarythingId = this.librarythingId,
isfdbId = this.isfdbId,
openlibraryId = this.openlibraryId,
noosfereId = this.noosfereId,
inventaireId = this.inventaireId,
language = this.language,
authors = this.authors.map { it.toAuthorDto() },
translators = this.translators.map { it.toAuthorDto() },
Expand All @@ -100,6 +112,10 @@ class Book(id: EntityID<UUID>) : UUIDEntity(id) {
googleId = this.googleId,
amazonId = this.amazonId,
librarythingId = this.librarythingId,
isfdbId = this.isfdbId,
openlibraryId = this.openlibraryId,
noosfereId = this.noosfereId,
inventaireId = this.inventaireId,
language = this.language,
authors = this.authors.map { it.toAuthorDto() },
translators = this.translators.map { it.toAuthorDto() },
Expand Down
Loading

0 comments on commit 1fdbf37

Please sign in to comment.