diff --git a/.github/scripts/commit-repo.sh b/.github/scripts/commit-repo.sh new file mode 100755 index 0000000..ab6163b --- /dev/null +++ b/.github/scripts/commit-repo.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +rsync -a --delete --exclude .git --exclude .gitignore ../master/repo/ . +git config --global user.email "github-actions[bot]@users.noreply.github.com" +git config --global user.name "github-actions[bot]" +git status +if [ -n "$(git status --porcelain)" ]; then + git add . + git commit -m "Update extensions repo" + git push +else + echo "No changes to commit" +fi diff --git a/.github/scripts/create-repo.sh b/.github/scripts/create-repo.sh new file mode 100755 index 0000000..db1a0bf --- /dev/null +++ b/.github/scripts/create-repo.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +mkdir -p repo/ + +cp -f server/build/server-1.0-all.jar repo/ \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1c188d6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + check_wrapper: + name: Validate Gradle Wrapper + runs-on: ubuntu-latest + + steps: + - name: Clone repo + uses: actions/checkout@v2 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + + build: + name: Build FatJar + needs: check_wrapper + if: "!startsWith(github.event.head_commit.message, '[SKIP CI]')" + runs-on: ubuntu-latest + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.5.0 + with: + access_token: ${{ github.token }} + + - name: Checkout master branch + uses: actions/checkout@v2 + with: + ref: master + path: master + + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: Build the Jar + uses: eskatos/gradle-command-action@v1 + with: + build-root-directory: master + wrapper-directory: master + arguments: :server:shadowJar + wrapper-cache-enabled: true + dependencies-cache-enabled: true + configuration-cache-enabled: true + + - name: Create repo artifacts + if: github.event_name == 'push' && github.repository == 'AriaMoradi/Tachidesk' + run: | + cd master + ./.github/scripts/create-repo.sh + + - name: Checkout repo branch + if: github.event_name == 'push' && github.repository == 'AriaMoradi/Tachidesk' + uses: actions/checkout@v2 + with: + ref: repo + path: repo + + - name: Deploy repo + if: github.event_name == 'push' && github.repository == 'AriaMoradi/Tachidesk' + run: | + cd repo + ../master/.github/scripts/commit-repo.sh diff --git a/server/src/main/kotlin/ir/armor/tachidesk/Main.kt b/server/src/main/kotlin/ir/armor/tachidesk/Main.kt index 965f2f4..a10d0db 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/Main.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/Main.kt @@ -94,9 +94,30 @@ class Main { val mangaId = ctx.pathParam("mangaId").toInt() ctx.json(getPages(chapterId, mangaId)) } + + // global search + app.get("/api/v1/search/:searchTerm") { ctx -> + val searchTerm = ctx.pathParam("searchTerm") + ctx.json(sourceGlobalSearch(searchTerm)) + } + + // single source search + app.get("/api/v1/source/:sourceId/search/:searchTerm") { ctx -> + val sourceId = ctx.pathParam("sourceId").toLong() + val searchTerm = ctx.pathParam("searchTerm") + ctx.json(sourceSearch(sourceId, searchTerm)) + } + + // source filter list + app.get("/api/v1/source/:sourceId/filters/") { ctx -> + val sourceId = ctx.pathParam("sourceId").toLong() + ctx.json(sourceFilters(sourceId)) + } + + + + } - - } } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/util/Search.kt b/server/src/main/kotlin/ir/armor/tachidesk/util/Search.kt new file mode 100644 index 0000000..77b56d0 --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/util/Search.kt @@ -0,0 +1,59 @@ +package ir.armor.tachidesk.util + +import eu.kanade.tachiyomi.source.model.Filter +import eu.kanade.tachiyomi.source.model.FilterList + +fun sourceFilters(sourceId: Long) { + val source = getHttpSource(sourceId) + source.getFilterList().toItems() +} + +fun sourceSearch(sourceId: Long, searchTerm: String) { + val source = getHttpSource(sourceId) + //source.fetchSearchManga() +} + +fun sourceGlobalSearch(searchTerm: String) { + +} + +data class FilterWrapper( + val type: String, + val filter: Any +) + +private fun FilterList.toItems(): List { + return mapNotNull { filter -> + when (filter) { + is Filter.Header -> FilterWrapper("Header",filter) + is Filter.Separator -> FilterWrapper("Separator",filter) + is Filter.CheckBox -> FilterWrapper("CheckBox",filter) + is Filter.TriState -> FilterWrapper("TriState",filter) + is Filter.Text -> FilterWrapper("Text",filter) + is Filter.Select<*> -> FilterWrapper("Select",filter) + is Filter.Group<*> -> { + val group = GroupItem(filter) + val subItems = filter.state.mapNotNull { + when (it) { + is Filter.CheckBox -> FilterWrapper("CheckBox",filter) + is Filter.TriState -> FilterWrapper("TriState",filter) + is Filter.Text -> FilterWrapper("Text",filter) + is Filter.Select<*> -> FilterWrapper("Select",filter) + else -> null + } as? ISectionable<*, *> + } + subItems.forEach { it.header = group } + group.subItems = subItems + group + } + is Filter.Sort -> { + val group = SortGroup(filter) + val subItems = filter.values.map { + SortItem(it, group) + } + group.subItems = subItems + group + } + } + } +} \ No newline at end of file