├── .eslintrc.js ├── .github ├── dependabot.yml └── workflows │ ├── build_release.yml │ ├── ci-js.yml │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── appinfo ├── info.xml └── routes.php ├── babel.config.js ├── composer.json ├── composer.lock ├── jsconfig.json ├── lib ├── Controller │ ├── EpisodeActionController.php │ ├── PersonalSettingsController.php │ └── SubscriptionChangeController.php ├── Core │ ├── EpisodeAction │ │ ├── EpisodeAction.php │ │ ├── EpisodeActionReader.php │ │ └── EpisodeActionSaver.php │ ├── PodcastData │ │ ├── PodcastActionCounts.php │ │ ├── PodcastData.php │ │ ├── PodcastDataReader.php │ │ ├── PodcastMetrics.php │ │ └── PodcastMetricsReader.php │ └── SubscriptionChange │ │ ├── SubscriptionChange.php │ │ ├── SubscriptionChangeRequestParser.php │ │ ├── SubscriptionChangeSaver.php │ │ └── SubscriptionChangesReader.php ├── Db │ ├── EpisodeAction │ │ ├── EpisodeActionEntity.php │ │ ├── EpisodeActionMapper.php │ │ ├── EpisodeActionRepository.php │ │ └── EpisodeActionWriter.php │ └── SubscriptionChange │ │ ├── SubscriptionChangeEntity.php │ │ ├── SubscriptionChangeMapper.php │ │ ├── SubscriptionChangeRepository.php │ │ └── SubscriptionChangeWriter.php ├── Migration │ ├── TimestampMigration.php │ ├── Version0001Date20210520063113.php │ ├── Version0002Date20210524131313.php │ ├── Version0003Date20210822231113.php │ ├── Version0004Date20210823115513.php │ ├── Version0005Date20211004110900.php │ ├── Version0006Date20221106215500.php │ └── Version0007Date202211111100.php ├── Sections │ └── GPodderSyncPersonal.php └── Settings │ └── GPodderSyncPersonal.php ├── package-lock.json ├── package.json ├── src ├── components │ └── SubscriptionListItem.vue ├── personalSettings.js └── views │ └── PersonalSettingsPage.vue ├── stylelint.config.js ├── templates └── settings │ └── personal.php ├── tests ├── Helper │ ├── DatabaseTransaction.php │ └── Writer │ │ └── TestWriter.php ├── Integration │ ├── AppTest.php │ ├── Controller │ │ ├── EpisodeActionControllerTest.php │ │ └── SubscriptionChangeControllerTest.php │ ├── EpisodeActionGuidMigrationTest.php │ ├── EpisodeActionRepositoryTest.php │ ├── EpisodeActionSaverGuidBackwardCompatibilityTest.php │ ├── EpisodeActionSaverGuidMigrationTest.php │ └── Migration │ │ ├── SubscriptionMigrationTest.php │ │ └── TimestampMigrationTest.php ├── Unit │ └── Core │ │ ├── EpisodeAction │ │ ├── EpisodeActionReaderTest.php │ │ └── EpisodeActionTest.php │ │ ├── PodcastData │ │ └── PodcastDataTest.php │ │ └── SubscriptionChange │ │ ├── SubscriptionChangeReaderTest.php │ │ └── SubscriptionChangeRequestParserTest.php ├── bootstrap.php └── phpunit.xml └── webpack.config.js /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '@nextcloud', 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | # Maintain dependencies for npm 9 | - package-ecosystem: "npm" 10 | directory: "/js" 11 | schedule: 12 | interval: "daily" 13 | labels: 14 | - "dependencies" 15 | - "Skip-Changelog" 16 | versioning-strategy: increase 17 | 18 | # Maintain dependencies for Composer 19 | - package-ecosystem: "composer" 20 | directory: "/" 21 | schedule: 22 | interval: "daily" 23 | labels: 24 | - "dependencies" 25 | - "Skip-Changelog" 26 | versioning-strategy: increase 27 | 28 | # Maintain dependencies for GitHub Actions 29 | - package-ecosystem: "github-actions" 30 | directory: "/" 31 | schedule: 32 | interval: "daily" 33 | labels: 34 | - "dependencies" 35 | - "Skip-Changelog" 36 | -------------------------------------------------------------------------------- /.github/workflows/build_release.yml: -------------------------------------------------------------------------------- 1 | name: Build and publish app release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | env: 8 | APP_NAME: gpoddersync 9 | 10 | jobs: 11 | build_and_publish: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | with: 17 | path: ${{ env.APP_NAME }} 18 | - name: Install NPM packages 19 | run: cd ${{ env.APP_NAME }} && make npm-init 20 | - name: Build JS 21 | run: cd ${{ env.APP_NAME }} && make build-js-production 22 | - name: Create release tarball 23 | run: cd ${{ env.APP_NAME }} && make appstore 24 | - name: Upload app tarball to release 25 | uses: svenstaro/upload-release-action@v2 26 | id: attach_to_release 27 | with: 28 | repo_token: ${{ secrets.GITHUB_TOKEN }} 29 | file: ${{ env.APP_NAME }}/build/artifacts/${{ env.APP_NAME }}.tar.gz 30 | asset_name: ${{ env.APP_NAME }}.tar.gz 31 | tag: ${{ github.ref }} 32 | overwrite: true 33 | - name: Upload app to Nextcloud appstore 34 | uses: R0Wi/nextcloud-appstore-push-action@v1.0.4 35 | with: 36 | app_name: ${{ env.APP_NAME }} 37 | appstore_token: ${{ secrets.APPSTORE_TOKEN }} 38 | download_url: ${{ steps.attach_to_release.outputs.browser_download_url }} 39 | app_private_key: ${{ secrets.APP_PRIVATE_KEY }} 40 | nightly: false 41 | -------------------------------------------------------------------------------- /.github/workflows/ci-js.yml: -------------------------------------------------------------------------------- 1 | name: NPM build 2 | 3 | on: 4 | pull_request: 5 | 6 | env: 7 | APP_NAME: gpoddersync 8 | 9 | jobs: 10 | js: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | with: 17 | path: ${{ env.APP_NAME }} 18 | - name: Install NPM packages 19 | run: cd ${{ env.APP_NAME }} && make npm-init 20 | - name: Build JS 21 | run: cd ${{ env.APP_NAME }} && make build-js-production 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: PHPUnit 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | - "ci-*" 9 | 10 | env: 11 | APP_NAME: gpoddersync 12 | 13 | jobs: 14 | php: 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | # do not stop on another job's failure 19 | fail-fast: false 20 | matrix: 21 | php-versions: ["8.1", "8.2"] 22 | databases: ["sqlite"] 23 | server-versions: 24 | ["stable27", "stable28", "stable29", "stable30", "stable31"] 25 | 26 | name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }} 27 | 28 | steps: 29 | - name: Checkout server 30 | uses: actions/checkout@v4 31 | with: 32 | repository: nextcloud/server 33 | ref: ${{ matrix.server-versions }} 34 | 35 | - name: Checkout submodules 36 | shell: bash 37 | run: | 38 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 39 | git submodule sync --recursive 40 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 41 | 42 | - name: Checkout app 43 | uses: actions/checkout@v4 44 | with: 45 | path: apps/${{ env.APP_NAME }} 46 | 47 | - name: Set up php ${{ matrix.php-versions }} 48 | uses: shivammathur/setup-php@v2 49 | with: 50 | php-version: ${{ matrix.php-versions }} 51 | extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, gd, zip 52 | coverage: none 53 | 54 | - name: Set up PHPUnit 55 | working-directory: apps/${{ env.APP_NAME }} 56 | run: composer i 57 | 58 | - name: Set up Nextcloud 59 | env: 60 | DB_PORT: 4444 61 | run: | 62 | mkdir data 63 | ./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password 64 | php -f index.php 65 | ./occ app:enable --force ${{ env.APP_NAME }} 66 | php -S localhost:8080 & 67 | 68 | - name: PHPUnit 69 | working-directory: apps/${{ env.APP_NAME }} 70 | run: ./vendor/bin/phpunit -c tests/phpunit.xml 71 | 72 | mysql: 73 | runs-on: ubuntu-latest 74 | 75 | strategy: 76 | # do not stop on another job's failure 77 | fail-fast: false 78 | matrix: 79 | php-versions: ["8.1", "8.2"] 80 | databases: ["mysql"] 81 | server-versions: ["stable27", "stable28", "stable29", "stable30"] 82 | 83 | name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }} 84 | 85 | services: 86 | mysql: 87 | image: mariadb:10.5 88 | ports: 89 | - 4444:3306/tcp 90 | env: 91 | MYSQL_ROOT_PASSWORD: rootpassword 92 | options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5 93 | 94 | steps: 95 | - name: Checkout server 96 | uses: actions/checkout@v4 97 | with: 98 | repository: nextcloud/server 99 | ref: ${{ matrix.server-versions }} 100 | 101 | - name: Checkout submodules 102 | shell: bash 103 | run: | 104 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 105 | git submodule sync --recursive 106 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 107 | 108 | - name: Checkout app 109 | uses: actions/checkout@v4 110 | with: 111 | path: apps/${{ env.APP_NAME }} 112 | 113 | - name: Set up php ${{ matrix.php-versions }} 114 | uses: shivammathur/setup-php@v2 115 | with: 116 | php-version: ${{ matrix.php-versions }} 117 | extensions: mbstring, iconv, fileinfo, intl, mysql, pdo_mysql, gd, zip 118 | coverage: none 119 | 120 | - name: Set up PHPUnit 121 | working-directory: apps/${{ env.APP_NAME }} 122 | run: composer i 123 | 124 | - name: Set up Nextcloud 125 | env: 126 | DB_PORT: 4444 127 | run: | 128 | mkdir data 129 | ./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password 130 | php -f index.php 131 | ./occ app:enable --force ${{ env.APP_NAME }} 132 | php -S localhost:8080 & 133 | 134 | - name: PHPUnit 135 | working-directory: apps/${{ env.APP_NAME }} 136 | run: ./vendor/bin/phpunit -c tests/phpunit.xml 137 | 138 | pgsql: 139 | runs-on: ubuntu-latest 140 | 141 | strategy: 142 | # do not stop on another job's failure 143 | fail-fast: false 144 | matrix: 145 | php-versions: ["8.1", "8.2"] 146 | databases: ["pgsql"] 147 | server-versions: ["stable27", "stable28", "stable29", "stable30"] 148 | 149 | name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }} 150 | 151 | services: 152 | postgres: 153 | image: postgres:14.5 154 | ports: 155 | - 4444:5432/tcp 156 | env: 157 | POSTGRES_USER: root 158 | POSTGRES_PASSWORD: rootpassword 159 | POSTGRES_DB: nextcloud 160 | options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 161 | 162 | steps: 163 | - name: Checkout server 164 | uses: actions/checkout@v4 165 | with: 166 | repository: nextcloud/server 167 | ref: ${{ matrix.server-versions }} 168 | 169 | - name: Checkout submodules 170 | shell: bash 171 | run: | 172 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 173 | git submodule sync --recursive 174 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 175 | 176 | - name: Checkout app 177 | uses: actions/checkout@v4 178 | with: 179 | path: apps/${{ env.APP_NAME }} 180 | 181 | - name: Set up php ${{ matrix.php-versions }} 182 | uses: shivammathur/setup-php@v2 183 | with: 184 | php-version: ${{ matrix.php-versions }} 185 | extensions: mbstring, iconv, fileinfo, intl, pgsql, pdo_pgsql, gd, zip 186 | coverage: none 187 | 188 | - name: Set up PHPUnit 189 | working-directory: apps/${{ env.APP_NAME }} 190 | run: composer i 191 | 192 | - name: Set up Nextcloud 193 | env: 194 | DB_PORT: 4444 195 | run: | 196 | mkdir data 197 | ./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password 198 | php -f index.php 199 | ./occ app:enable --force ${{ env.APP_NAME }} 200 | php -S localhost:8080 & 201 | 202 | - name: PHPUnit 203 | working-directory: apps/${{ env.APP_NAME }} 204 | run: ./vendor/bin/phpunit -c tests/phpunit.xml 205 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/* 2 | tests/.phpunit.result.cache 3 | node_modules/ 4 | js/ 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 3.12.0 - 2025-02-16 4 | ### Changed 5 | - Add support for Nextcloud 31 6 | 7 | ## 3.11.0 - 2024-12-01 8 | ### Changed 9 | - Always respond with timezone in timestamps 10 | ### Fixed 11 | - Don't crash when receiving ISO8601 timestamps containing a timezone 12 | 13 | ## 3.10.0 - 2024-09-23 14 | ### Changed 15 | - Add support for Nextcloud 30 16 | 17 | ## 3.9.0 - 2024-05-21 18 | ### Changed 19 | - Add support for Nextcloud 29 20 | - Drop support for Nextcloud 26 21 | - Drop support for php8.0 22 | 23 | ## 3.8.3 - 2024-01-12 24 | ### Fixed 25 | - identify and delete conflicting episode by guid and not by episode url (thanks @LinAGKar) 26 | 27 | ## 3.8.2 - 2023-12-02 28 | ### Changed 29 | - add support for Nextcloud 28 30 | - drop support for Nextcloud 25 31 | 32 | ## 3.8.1 - 2023-06-18 33 | ### Changed 34 | - add support for Nextcloud 27 35 | - drop support for Nextcloud 24 36 | 37 | ## 3.8.0 - 2023-03-23 38 | ### Changed 39 | - drop php7.4 support 40 | - add support for Nextcloud 26 41 | 42 | ## 3.7.3 - 2023-02-24 43 | ### Fixed 44 | - If EpisodeAction is updated with new episode url and there is a conflicting EpisodeAction with that same episode url the later will be deleted 45 | 46 | 47 | ## 3.7.2 - 2023-02-24 48 | ### Fixed 49 | - EpisodeActions are explicitly searched in database by guid. Episode url is used as fallback. Combined search produces multiple results thus broke synchronization 50 | 51 | ## 3.7.1 - 2022-11-11 52 | ### Fixed 53 | - Fix error where app couldn't be installed with some databases 54 | 55 | ## 3.7.0 - 2022-11-10 56 | ### Fixed 57 | - Podcast overview page no longer produces errors when using php8.X 58 | ### Changed 59 | - Allow longer feed URLs with up to 1000 characters 60 | 61 | ## 3.6.0 - 2022-10-28 62 | ### Added 63 | - New overview page of synchronized data in personal settings (thanks @jilleJr) 64 | 65 | ## 3.5.0 - 2022-10-18 66 | ### Changed 67 | - Add support for Nextcloud 25 68 | 69 | ## 3.4.0 - 2022-05-26 70 | ### Fixed 71 | - Don't crash if no sync timestamp is passed 72 | ### Changed 73 | - Return all entries on list actions if no timestamp is passed 74 | 75 | ## 3.3.0 - 2022-05-03 76 | ### Fixed 77 | - Don't crash on unauthenticated api call 78 | ### Changed 79 | - Add support for Nextcloud 24 80 | 81 | ## 3.2.0 - 2021-12-09 82 | ### Changed 83 | - Ignore subscriptions that have no url 84 | - Add support for Nextcloud 23 85 | 86 | ## 3.1.0 - 2021-10-18 87 | ### Changed 88 | - Add timestamp to subscription change response @JonOfUs 89 | 90 | ## 3.0.1 - 2021-10-13 91 | ### Fixed 92 | - Timestamp migration writes correct values to database @JonOfUs 93 | 94 | ## 3.0.0 - 2021-10-06 95 | ### Changed 96 | - EpisodeAction upload now expects JSON similar to gpodder.net (see README) 97 | - expanded minimal API documentation (see README) 98 | - query episodes by UNIX time instead of DateTime 99 | 100 | ## 2.0.0 - 2021-08-29 101 | ### Changed 102 | - add field "guid" to episode_action 103 | - identify episode actions by guid. episode_action.episode (episode url) serves as fallback if no guid is provided. 104 | 105 | ## 1.0.14 - 2021-08-24 106 | ### Fixed 107 | - enable processing of multiple EpisodeActions (thanks https://github.com/JonOfUs) 108 | 109 | ## 1.0.13 - 2021-08-22 110 | ### Fixed 111 | - increase table column episode_action.action length limit to fit episode actions like DOWNLOAD 112 | ### Changed 113 | - narrow catch to nextcloud dbal exceptions 114 | 115 | ## 1.0.12 - 2021-08-21 116 | ### Fixed 117 | - handle UniqueConstraintViolationException thrown by nc < v22.0 118 | 119 | 120 | ## 1.0.11 - 2021-08-16 121 | ### Fixed 122 | - stop creating unnecessary log file in nextcloud root folder 123 | 124 | ## 1.0.10 - 2021-08-14 125 | ### Fixed 126 | - return all subscriptions and episode changes for parameter since=0 127 | 128 | 129 | ## 1.0.9 - 2021-07-27 130 | ### Changed 131 | - save episode action timestamps as UTC (thanks @JohnOfUs) 132 | 133 | ## 1.0.8 - 2021-07-22 134 | ### Fixed 135 | - convert timestamp from episode action request to format also mysql can process (#13) 136 | 137 | 138 | ## 1.0.7 – 2021-07-13 139 | ### Changed 140 | - accept only arrays on subscription change endpoint (thanks https://github.com/mattsches) 141 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the project 2 | 3 | app_name=gpoddersync 4 | 5 | project_dir=$(CURDIR)/../$(app_name) 6 | build_dir=$(CURDIR)/build/artifacts 7 | appstore_dir=$(build_dir)/appstore 8 | source_dir=$(build_dir)/source 9 | sign_dir=$(build_dir)/sign 10 | package_name=$(app_name) 11 | cert_dir=$(HOME)/.nextcloud/certificates 12 | version+=master 13 | 14 | all: dev-setup build-js-production 15 | 16 | dev-setup: clean-dev npm-init 17 | 18 | dependabot: dev-setup npm-update build-js-production 19 | 20 | release: appstore create-tag 21 | 22 | build-js: 23 | npm run dev 24 | 25 | build-js-production: 26 | npm run build 27 | 28 | watch-js: 29 | npm run watch 30 | 31 | test: 32 | npm run test:unit 33 | 34 | lint: 35 | npm run lint 36 | 37 | lint-fix: 38 | npm run lint:fix 39 | 40 | npm-init: 41 | npm ci 42 | 43 | npm-update: 44 | npm update 45 | 46 | clean: 47 | rm -rf js/* 48 | rm -rf $(build_dir) 49 | 50 | clean-dev: clean 51 | rm -rf node_modules 52 | 53 | create-tag: 54 | git tag -a v$(version) -m "Tagging the $(version) release." 55 | git push origin v$(version) 56 | 57 | appstore: 58 | rm -rf $(build_dir) 59 | mkdir -p $(sign_dir) 60 | rsync -a \ 61 | --exclude=babel.config.js \ 62 | --exclude=/build \ 63 | --exclude=composer.json \ 64 | --exclude=composer.lock \ 65 | --exclude=docs \ 66 | --exclude=.drone.yml \ 67 | --exclude=.eslintignore \ 68 | --exclude=.eslintrc.js \ 69 | --exclude=.git \ 70 | --exclude=.gitattributes \ 71 | --exclude=.github \ 72 | --exclude=.gitignore \ 73 | --exclude=jest.config.js \ 74 | --exclude=.l10nignore \ 75 | --exclude=mkdocs.yml \ 76 | --exclude=Makefile \ 77 | --exclude=node_modules \ 78 | --exclude=package.json \ 79 | --exclude=package-lock.json \ 80 | --exclude=.php_cs.dist \ 81 | --exclude=.php_cs.cache \ 82 | --exclude=README.md \ 83 | --exclude=src \ 84 | --exclude=.stylelintignore \ 85 | --exclude=stylelint.config.js \ 86 | --exclude=.tx \ 87 | --exclude=tests \ 88 | --exclude=vendor \ 89 | --exclude=releases \ 90 | --exclude=webpack.*.js \ 91 | $(project_dir)/ $(sign_dir)/$(app_name) 92 | @if [ -f $(cert_dir)/$(app_name).key ]; then \ 93 | echo "Signing app files…"; \ 94 | php ../../occ integrity:sign-app \ 95 | --privateKey=$(cert_dir)/$(app_name).key\ 96 | --certificate=$(cert_dir)/$(app_name).crt\ 97 | --path=$(sign_dir)/$(app_name); \ 98 | fi 99 | tar -czf $(build_dir)/$(app_name).tar.gz \ 100 | -C $(sign_dir) $(app_name) 101 | @if [ -f $(cert_dir)/$(app_name).key ]; then \ 102 | echo "Signing package…"; \ 103 | openssl dgst -sha512 -sign $(cert_dir)/$(app_name).key $(build_dir)/$(app_name).tar.gz | openssl base64; \ 104 | fi 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nextcloud-gpodder 2 | Nextcloud app that replicates basic gpodder.net api to sync podcast consumer apps (podcatchers) like AntennaPod. 3 | 4 | ### Clients supporting sync 5 | | client | support status | 6 | | :- | :- | 7 | | [AntennaPod](https://antennapod.org) | Initial purpose for this project, as a synchronization endpoint for this client.
Support is available [as of version 2.5.1](https://github.com/AntennaPod/AntennaPod/pull/5243/). | 8 | | [KDE Kasts](https://apps.kde.org/de/kasts/) | Supported since version 21.12 | 9 | | [Podcast Merlin](https://github.com/yoyoooooooooo/Podcast-Merlin--Nextcloud-Gpodder-Client-For-Windows) | Full sync support podcast client for Windows | 10 | | [RePod](https://apps.nextcloud.com/apps/repod) | Nextcloud app for playing and managing podcasts with sync support | 11 | | [Cardo](https://cardo-podcast.github.io/#/cardo) | Podcast client with sync support, for Windows, Mac and Linux | 12 | | [FocusPodcast](https://github.com/allentown521/FocusPodcast) | Fork of AntennaPod, with a focus on UI and customization | 13 | | [Podcini.X](https://github.com/XilinJia/Podcini.X) | Fork of AntennaPod, with a focus on many features. Synchronization is not yet stable. | 14 | | ~~[Garmin Podcasts](https://lucasasselli.github.io/garmin-podcasts/)~~ | Repository archived, app is [no longer available](https://apps.garmin.com/en-US/apps/b5b85600-0625-43b6-89e9-1245bd44532c) | 15 | ### Installation 16 | Either from the official Nextcloud app store ([link to app page](https://apps.nextcloud.com/apps/gpoddersync)) or by downloading the [latest release](https://github.com/thrillfall/nextcloud-gpodder/releases/latest) and extracting it into your Nextcloud apps/ directory. 17 | 18 | ## API 19 | ### subscription 20 | * **get subscription changes**: `GET /index.php/apps/gpoddersync/subscriptions` 21 | * *(optional)* GET parameter `since` (UNIX time) 22 | * **upload subscription changes** : `POST /index.php/apps/gpoddersync/subscription_change/create` 23 | * returns JSON with current timestamp 24 | 25 | The API replicates this: https://gpoddernet.readthedocs.io/en/latest/api/reference/subscriptions.html 26 | 27 | #### Example requests: 28 | ```json 29 | GET /index.php/apps/gpoddersync/subscriptions?since=1633240761 30 | 31 | { 32 | "add": [ 33 | "https://example.com/feed.xml", 34 | "https://example.org/feed/" 35 | ], 36 | "remove": [ 37 | "https://example.net/feed.rss" 38 | ], 39 | "timestamp": 1663540502 40 | } 41 | ``` 42 | ```json 43 | POST /index.php/apps/gpoddersync/subscription_change/create 44 | 45 | { 46 | "add": [ 47 | "https://example.com/feed.xml", 48 | "https://example.org/feed/" 49 | ], 50 | "remove": [ 51 | "https://example.net/feed.rss" 52 | ] 53 | } 54 | ``` 55 | 56 | ### episode action 57 | * **get episode actions**: `GET /index.php/apps/gpoddersync/episode_action` 58 | * *(optional)* GET parameter `since` (UNIX time) 59 | * fields: *podcast*, *episode*, *guid*, *action*, *timestamp*, *position*, *started*, *total* 60 | * **create episode actions**: `POST /index.php/apps/gpoddersync/episode_action/create` 61 | * fields: *podcast*, *episode*, *guid*, *action*, *timestamp*, *position*, *started*, *total* 62 | * *position*, *started* and *total* are optional, default value is -1 63 | * *guid* is also optional, but should be sent if available 64 | * identification is done by *guid*, or *episode* if *guid* is missing 65 | * returns JSON with current timestamp 66 | 67 | The API replicates this: https://gpoddernet.readthedocs.io/en/latest/api/reference/events.html 68 | 69 | #### Example requests: 70 | ```json 71 | GET /index.php/apps/gpoddersync/episode_action?since=1633240761 72 | 73 | { 74 | "actions": [ 75 | { 76 | "podcast": "http://example.com/feed.rss", 77 | "episode": "http://example.com/files/s01e20.mp3", 78 | "guid": "s01e20-example-org", 79 | "action": "PLAY", 80 | "timestamp": "2009-12-12T09:00:00", 81 | "started": 15, 82 | "position": 120, 83 | "total": 500 84 | }, 85 | { 86 | "podcast": "http://example.com/feed.rss", 87 | "episode": "http://example.com/files/s01e20.mp3", 88 | "guid": "s01e20-example-org", 89 | "action": "DOWNLOAD", 90 | "timestamp": "2009-12-12T09:00:00", 91 | "started": -1, 92 | "position": -1, 93 | "total": -1 94 | }, 95 | ], 96 | "timestamp": 12345 97 | } 98 | ``` 99 | ```json 100 | POST /index.php/apps/gpoddersync/episode_action/create 101 | 102 | [ 103 | { 104 | "podcast": "http://example.com/feed.rss", 105 | "episode": "http://example.com/files/s01e20.mp3", 106 | "guid": "s01e20-example-org", 107 | "action": "play", 108 | "timestamp": "2009-12-12T09:00:00", 109 | "started": 15, 110 | "position": 120, 111 | "total": 500 112 | }, 113 | { 114 | "podcast": "http://example.org/podcast.php", 115 | "episode": "http://ftp.example.org/foo.ogg", 116 | "guid": "foo-bar-123", 117 | "action": "DOWNLOAD", 118 | "timestamp": "2009-12-12T09:05:21", 119 | } 120 | ] 121 | ``` 122 | 123 | ## Development 124 | 125 | ### Testing 126 | - mount project into apps-extra of nextcloud environment (https://github.com/juliushaertl/nextcloud-docker-dev) 127 | - `docker-compose exec nextcloud occ app:enable gpoddersync` enable app so we have database tables 128 | - `docker-compose exec nextcloud phpunit9 -c apps-extra/nextcloud-gpodder/tests/phpunit.xml` 129 | -------------------------------------------------------------------------------- /appinfo/info.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | gpoddersync 5 | GPodder Sync 6 | replicate basic GPodder.net API 7 | 8 | 3.12.0 9 | agpl 10 | Thrillfall 11 | GPodderSync 12 | integration 13 | multimedia 14 | https://github.com/thrillfall/nextcloud-gpodder 15 | https://github.com/thrillfall/nextcloud-gpodder/issues 16 | 17 | https://github.com/thrillfall/nextcloud-gpodder/blob/main/README.md#api 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | OCA\GPodderSync\Migration\TimestampMigration 26 | 27 | 28 | 29 | OCA\GPodderSync\Settings\GPodderSyncPersonal 30 | OCA\GPodderSync\Sections\GPodderSyncPersonal 31 | 32 | 33 | -------------------------------------------------------------------------------- /appinfo/routes.php: -------------------------------------------------------------------------------- 1 | OCA\GPodderSync\Controller\PageController->index() 6 | * 7 | * The controller class has to be registered in the application.php file since 8 | * it's instantiated in there 9 | */ 10 | return [ 11 | 'routes' => [ 12 | ['name' => 'episode_action#create', 'url' => '/episode_action/create', 'verb' => 'POST'], 13 | ['name' => 'episode_action#list', 'url' => '/episode_action', 'verb' => 'GET'], 14 | 15 | ['name' => 'subscription_change#list', 'url' => '/subscriptions', 'verb' => 'GET'], 16 | ['name' => 'subscription_change#create', 'url' => '/subscription_change/create', 'verb' => 'POST'], 17 | ['name' => 'personal_settings#metrics', 'url' => '/personal_settings/metrics', 'verb' => 'GET'], 18 | ['name' => 'personal_settings#podcastData', 'url' => '/personal_settings/podcast_data', 'verb' => 'GET'], 19 | ] 20 | ]; 21 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | const babelConfig = require('@nextcloud/babel-config') 2 | 3 | module.exports = babelConfig 4 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thrillfall/gpoddersync", 3 | "type": "project", 4 | "license": "AGPLv3", 5 | "authors": [ 6 | { 7 | "name": "thrillfall", 8 | "email": "thrillfall@disroot.org" 9 | }, 10 | { 11 | "name": "JonOfUs", 12 | "email": "jonofus@flueren.eu" 13 | } 14 | ], 15 | "require-dev": { 16 | "phpunit/phpunit": "^9" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "jsx": "preserve" 6 | }, 7 | "exclude": [ 8 | "node_modules" 9 | ], 10 | "include": [ 11 | "src/**/*" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /lib/Controller/EpisodeActionController.php: -------------------------------------------------------------------------------- 1 | episodeActionRepository = $episodeActionRepository; 29 | $this->userId = $UserId ?? ''; 30 | $this->episodeActionSaver = $episodeActionSaver; 31 | $this->request = $request; 32 | } 33 | 34 | /** 35 | * 36 | * @NoAdminRequired 37 | * @NoCSRFRequired 38 | * 39 | * @return JSONResponse 40 | */ 41 | public function create(): JSONResponse { 42 | 43 | $episodeActionsArray = $this->filterEpisodesFromRequestParams($this->request->getParams()); 44 | $this->episodeActionSaver->saveEpisodeActions($episodeActionsArray, $this->userId); 45 | 46 | return new JSONResponse(["timestamp" => time()]); 47 | } 48 | 49 | /** 50 | * @NoAdminRequired 51 | * @NoCSRFRequired 52 | * 53 | * @param int $since 54 | * @return JSONResponse 55 | */ 56 | public function list(int $since = 0): JSONResponse { 57 | $episodeActions = $this->episodeActionRepository->findAll($since, $this->userId); 58 | $untypedEpisodeActionData = []; 59 | 60 | foreach ($episodeActions as $episodeAction) { 61 | $untypedEpisodeActionData[] = $episodeAction->toArray(); 62 | } 63 | 64 | return new JSONResponse([ 65 | "actions" => $untypedEpisodeActionData, 66 | "timestamp" => time() 67 | ]); 68 | } 69 | 70 | /** 71 | * @param array $data 72 | * @return array $episodeActionsArray 73 | */ 74 | public function filterEpisodesFromRequestParams(array $data): array { 75 | return array_filter($data, "is_numeric", ARRAY_FILTER_USE_KEY); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/Controller/PersonalSettingsController.php: -------------------------------------------------------------------------------- 1 | userId = $UserId ?? ''; 29 | $this->metricsReader = $metricsReader; 30 | $this->dataReader = $dataReader; 31 | } 32 | 33 | /** 34 | * 35 | * @NoAdminRequired 36 | * @NoCSRFRequired 37 | * 38 | * @return JSONResponse 39 | */ 40 | public function metrics(): JSONResponse { 41 | $metrics = $this->metricsReader->metrics($this->userId); 42 | return new JSONResponse([ 43 | 'subscriptions' => $metrics, 44 | ]); 45 | } 46 | 47 | /** 48 | * @NoAdminRequired 49 | * @NoCSRFRequired 50 | * 51 | * @param string $url 52 | * @return JsonResponse 53 | */ 54 | public function podcastData(string $url = ''): JsonResponse { 55 | if ($url === '') { 56 | return new JSONResponse([ 57 | 'message' => "Missing query parameter 'url'.", 58 | 'data' => null, 59 | ], Http::STATUS_BAD_REQUEST); 60 | } 61 | return new JsonResponse([ 62 | 'data' => $this->dataReader->getCachedOrFetchPodcastData($url, $this->userId), 63 | ]); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lib/Controller/SubscriptionChangeController.php: -------------------------------------------------------------------------------- 1 | subscriptionChangeSaver = $subscriptionChangeSaver; 30 | $this->subscriptionChangeRepository = $subscriptionChangeRepository; 31 | $this->userId = $UserId ?? ''; 32 | } 33 | 34 | /** 35 | * 36 | * @NoAdminRequired 37 | * @NoCSRFRequired 38 | * 39 | * @param array $add 40 | * @param array $remove 41 | * @return JSONResponse 42 | */ 43 | public function create(array $add, array $remove): JSONResponse { 44 | $this->subscriptionChangeSaver->saveSubscriptionChanges($add, $remove, $this->userId); 45 | 46 | return new JSONResponse(["timestamp" => time()]); 47 | } 48 | 49 | /** 50 | * 51 | * @NoAdminRequired 52 | * @NoCSRFRequired 53 | * 54 | * @param int|null $since 55 | * @return JSONResponse 56 | */ 57 | public function list(int $since = 0): JSONResponse { 58 | $sinceDatetime = (new DateTime)->setTimestamp($since); 59 | return new JSONResponse([ 60 | "add" => $this->extractUrlList($this->subscriptionChangeRepository->findAllSubscribed($sinceDatetime, $this->userId)), 61 | "remove" => $this->extractUrlList($this->subscriptionChangeRepository->findAllUnSubscribed($sinceDatetime, $this->userId)), 62 | "timestamp" => time() 63 | ]); 64 | } 65 | 66 | /** 67 | * @param array $allSubscribed 68 | * @return mixed 69 | */ 70 | private function extractUrlList(array $allSubscribed): array { 71 | return array_map(static function (SubscriptionChangeEntity $subscription) { 72 | return $subscription->getUrl(); 73 | }, $allSubscribed); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /lib/Core/EpisodeAction/EpisodeAction.php: -------------------------------------------------------------------------------- 1 | podcast = $podcast; 29 | $this->episode = $episode; 30 | $this->action = $action; 31 | $this->timestamp = $timestamp; 32 | $this->started = $started; 33 | $this->position = $position; 34 | $this->total = $total; 35 | $this->guid = $guid; 36 | $this->id = $id; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getPodcast(): string { 43 | return $this->podcast; 44 | } 45 | 46 | /** 47 | * @return string 48 | */ 49 | public function getEpisode(): string { 50 | return $this->episode; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getAction(): string { 57 | return $this->action; 58 | } 59 | 60 | /** 61 | * @return string 62 | */ 63 | public function getTimestamp(): string { 64 | return $this->timestamp; 65 | } 66 | 67 | /** 68 | * @return int 69 | */ 70 | public function getStarted(): int { 71 | return $this->started; 72 | } 73 | 74 | /** 75 | * @return int 76 | */ 77 | public function getPosition(): int { 78 | return $this->position; 79 | } 80 | 81 | /** 82 | * @return int 83 | */ 84 | public function getTotal(): int 85 | { 86 | return $this->total; 87 | } 88 | 89 | public function getGuid() : ?string 90 | { 91 | return $this->guid; 92 | } 93 | 94 | /** 95 | * @return int 96 | */ 97 | public function getId(): int 98 | { 99 | return $this->id; 100 | } 101 | 102 | public function toArray(): array { 103 | return 104 | [ 105 | 'podcast' => $this->getPodcast(), 106 | 'episode' => $this->getEpisode(), 107 | 'timestamp' => $this->getTimestamp(), 108 | 'guid' => $this->getGuid(), 109 | 'position' => $this->getPosition(), 110 | 'started' => $this->getStarted(), 111 | 'total' => $this->getTotal(), 112 | 'action' => $this->getAction(), 113 | ]; 114 | } 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /lib/Core/EpisodeAction/EpisodeActionReader.php: -------------------------------------------------------------------------------- 1 | hasRequiredProperties($episodeAction) === false) { 21 | throw new InvalidArgumentException(sprintf('Client sent incomplete or invalid data: %s', json_encode($episodeAction, JSON_THROW_ON_ERROR))); 22 | } 23 | $episodeActions[] = new EpisodeAction( 24 | $episodeAction["podcast"], 25 | $episodeAction["episode"], 26 | strtoupper($episodeAction["action"]), 27 | $episodeAction["timestamp"], 28 | $episodeAction["started"] ?? -1, 29 | $episodeAction["position"] ?? -1, 30 | $episodeAction["total"] ?? -1, 31 | $episodeAction["guid"] ?? null, 32 | null 33 | ); 34 | } 35 | 36 | return $episodeActions; 37 | } 38 | 39 | /** 40 | * @param array $episodeAction 41 | * @return bool 42 | */ 43 | private function hasRequiredProperties(array $episodeAction): bool { 44 | return (count(array_intersect($this->requiredProperties, array_keys($episodeAction))) === count($this->requiredProperties)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/Core/EpisodeAction/EpisodeActionSaver.php: -------------------------------------------------------------------------------- 1 | episodeActionRepository = $episodeActionRepository; 25 | $this->episodeActionWriter = $episodeActionWriter; 26 | $this->episodeActionReader = $episodeActionReader; 27 | } 28 | 29 | public function saveEpisodeActions( 30 | array $episodeActionsArray, 31 | string $userId 32 | ): array { 33 | $episodeActions = $this->episodeActionReader->fromArray( 34 | $episodeActionsArray 35 | ); 36 | 37 | $episodeActionEntities = []; 38 | 39 | foreach ($episodeActions as $episodeAction) { 40 | $episodeActionEntity = $this->hydrateEpisodeActionEntity( 41 | $episodeAction, 42 | $userId 43 | ); 44 | 45 | try { 46 | $episodeActionEntities[] = $this->episodeActionWriter->save( 47 | $episodeActionEntity 48 | ); 49 | } catch (Exception $exception) { 50 | if ( 51 | $exception->getReason() === 52 | Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION 53 | ) { 54 | $episodeActionEntities[] = $this->updateEpisodeAction( 55 | $episodeActionEntity, 56 | $userId 57 | ); 58 | } 59 | } 60 | } 61 | return $episodeActionEntities; 62 | } 63 | 64 | private function convertTimestampToUnixEpoch(string $timestamp): string 65 | { 66 | $dateTime = new DateTime( 67 | datetime: $timestamp, 68 | timezone: new DateTimeZone("UTC") 69 | ); 70 | return $dateTime->format("U"); 71 | } 72 | 73 | private function updateEpisodeAction( 74 | EpisodeActionEntity $episodeActionEntity, 75 | string $userId 76 | ): EpisodeActionEntity { 77 | $episodeActionToUpdate = $this->findEpisodeActionToUpdate( 78 | $episodeActionEntity, 79 | $userId 80 | ); 81 | 82 | $episodeActionEntity->setId($episodeActionToUpdate->getId()); 83 | 84 | $this->ensureGuidDoesNotGetNulledWithOldData( 85 | $episodeActionToUpdate, 86 | $episodeActionEntity 87 | ); 88 | 89 | try { 90 | return $this->episodeActionWriter->update($episodeActionEntity); 91 | } catch (Exception $exception) { 92 | if ( 93 | $exception->getReason() === 94 | Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION 95 | ) { 96 | $this->deleteConflictingEpisodeAction( 97 | $episodeActionEntity, 98 | $userId 99 | ); 100 | } 101 | } 102 | return $this->episodeActionWriter->update($episodeActionEntity); 103 | } 104 | 105 | private function ensureGuidDoesNotGetNulledWithOldData( 106 | EpisodeAction $episodeActionToUpdate, 107 | EpisodeActionEntity $episodeActionEntity 108 | ): void { 109 | $existingGuid = $episodeActionToUpdate->getGuid(); 110 | if ( 111 | $existingGuid !== null && 112 | $episodeActionEntity->getGuid() === null 113 | ) { 114 | $episodeActionEntity->setGuid($existingGuid); 115 | } 116 | } 117 | 118 | private function hydrateEpisodeActionEntity( 119 | EpisodeAction $episodeAction, 120 | string $userId 121 | ): EpisodeActionEntity { 122 | $episodeActionEntity = new EpisodeActionEntity(); 123 | $episodeActionEntity->setPodcast($episodeAction->getPodcast()); 124 | $episodeActionEntity->setEpisode($episodeAction->getEpisode()); 125 | $episodeActionEntity->setGuid($episodeAction->getGuid()); 126 | $episodeActionEntity->setAction($episodeAction->getAction()); 127 | $episodeActionEntity->setPosition($episodeAction->getPosition()); 128 | $episodeActionEntity->setStarted($episodeAction->getStarted()); 129 | $episodeActionEntity->setTotal($episodeAction->getTotal()); 130 | $episodeActionEntity->setTimestampEpoch( 131 | $this->convertTimestampToUnixEpoch($episodeAction->getTimestamp()) 132 | ); 133 | $episodeActionEntity->setUserId($userId); 134 | 135 | return $episodeActionEntity; 136 | } 137 | 138 | private function findEpisodeActionToUpdate( 139 | EpisodeActionEntity $episodeActionEntity, 140 | string $userId 141 | ): ?EpisodeAction { 142 | $episodeAction = null; 143 | if ($episodeActionEntity->getGuid() !== null) { 144 | $episodeAction = $this->episodeActionRepository->findByGuid( 145 | $episodeActionEntity->getGuid(), 146 | $userId 147 | ); 148 | } 149 | 150 | if ($episodeAction === null) { 151 | $episodeAction = $this->episodeActionRepository->findByEpisodeUrl( 152 | $episodeActionEntity->getEpisode(), 153 | $userId 154 | ); 155 | } 156 | 157 | return $episodeAction; 158 | } 159 | 160 | /** 161 | * @param EpisodeActionEntity $episodeActionEntity 162 | * @param string $userId 163 | * @return void 164 | */ 165 | private function deleteConflictingEpisodeAction( 166 | EpisodeActionEntity $episodeActionEntity, 167 | string $userId 168 | ): void { 169 | $collidingEpisodeActionId = $this->episodeActionRepository 170 | ->findByEpisodeUrl($episodeActionEntity->getEpisode(), $userId) 171 | ->getId(); 172 | if ($collidingEpisodeActionId !== $episodeActionEntity->getId()) { 173 | $this->episodeActionRepository->deleteEpisodeActionByEpisodeUrl( 174 | $episodeActionEntity->getEpisode(), 175 | $userId 176 | ); 177 | } 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /lib/Core/PodcastData/PodcastActionCounts.php: -------------------------------------------------------------------------------- 1 | delete++; break; 21 | case 'download': $this->download++; break; 22 | case 'flattr': $this->flattr++; break; 23 | case 'new': $this->new++; break; 24 | case 'play': $this->play++; break; 25 | } 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | public function toArray(): array { 32 | return [ 33 | 'delete' => $this->delete, 34 | 'download' => $this->download, 35 | 'flattr' => $this->flattr, 36 | 'new' => $this->new, 37 | 'play' => $this->play, 38 | ]; 39 | } 40 | 41 | /** 42 | * @return array 43 | */ 44 | public function jsonSerialize(): mixed { 45 | return $this->toArray(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/Core/PodcastData/PodcastData.php: -------------------------------------------------------------------------------- 1 | title = $title; 29 | $this->author = $author; 30 | $this->link = $link; 31 | $this->description = $description; 32 | $this->imageUrl = $imageUrl; 33 | $this->fetchedAtUnix = $fetchedAtUnix; 34 | $this->imageBlob = $imageBlob; 35 | } 36 | 37 | /** 38 | * @return PodcastData 39 | * @throws Exception if the XML data could not be parsed. 40 | */ 41 | public static function parseRssXml(string $xmlString, ?int $fetchedAtUnix = null): PodcastData { 42 | $xml = new SimpleXMLElement($xmlString); 43 | $channel = $xml->channel; 44 | return new PodcastData( 45 | self::stringOrNull($channel->title), 46 | self::getXPathContent($xml, '/rss/channel/itunes:author'), 47 | self::stringOrNull($channel->link), 48 | self::stringOrNull($channel->description), 49 | self::getXPathContent($xml, '/rss/channel/image/url') 50 | ?? self::getXPathAttribute($xml, '/rss/channel/itunes:image/@href'), 51 | $fetchedAtUnix ?? (new DateTime())->getTimestamp() 52 | ); 53 | } 54 | 55 | private static function stringOrNull($value): ?string { 56 | if ($value) { 57 | return (string)$value; 58 | } 59 | return null; 60 | } 61 | 62 | private static function getXPathContent(SimpleXMLElement $xml, string $xpath): ?string { 63 | $match = $xml->xpath($xpath); 64 | if ($match) { 65 | return (string)$match[0]; 66 | } 67 | return null; 68 | } 69 | 70 | private static function getXPathAttribute(SimpleXMLElement $xml, string $xpath): ?string { 71 | $match = $xml->xpath($xpath); 72 | if ($match) { 73 | return (string)$match[0][0]; 74 | } 75 | return null; 76 | } 77 | 78 | /** 79 | * @return string|null 80 | */ 81 | public function getTitle(): ?string { 82 | return $this->title; 83 | } 84 | 85 | /** 86 | * @return string|null 87 | */ 88 | public function getAuthor(): ?string { 89 | return $this->author; 90 | } 91 | 92 | /** 93 | * @return string|null 94 | */ 95 | public function getLink(): ?string { 96 | return $this->link; 97 | } 98 | 99 | /** 100 | * @return string|null 101 | */ 102 | public function getDescription(): ?string { 103 | return $this->description; 104 | } 105 | 106 | /** 107 | * @return string|null 108 | */ 109 | public function getImageUrl(): ?string { 110 | return $this->imageUrl; 111 | } 112 | 113 | /** 114 | * @return int|null 115 | */ 116 | public function getFetchedAtUnix(): ?int { 117 | return $this->fetchedAtUnix; 118 | } 119 | 120 | /** 121 | * @return string|null 122 | */ 123 | public function getImageBlob(): ?string { 124 | return $this->imageBlob; 125 | } 126 | 127 | /** 128 | * @param string $blob 129 | * @return void 130 | */ 131 | public function setImageBlob(?string $blob): void { 132 | $this->imageBlob = $blob; 133 | } 134 | 135 | /** 136 | * @return string 137 | */ 138 | public function __toString() : string { 139 | return $this->title ?? '/no title/'; 140 | } 141 | 142 | /** 143 | * @return array 144 | */ 145 | public function toArray(): array { 146 | return 147 | [ 148 | 'title' => $this->title, 149 | 'author' => $this->author, 150 | 'link' => $this->link, 151 | 'description' => $this->description, 152 | 'imageUrl' => $this->imageUrl, 153 | 'imageBlob' => $this->imageBlob, 154 | 'fetchedAtUnix' => $this->fetchedAtUnix, 155 | ]; 156 | } 157 | 158 | /** 159 | * @return array 160 | */ 161 | public function jsonSerialize(): array { 162 | return $this->toArray(); 163 | } 164 | 165 | /** 166 | * @return PodcastData 167 | */ 168 | public static function fromArray(array $data): PodcastData { 169 | return new PodcastData( 170 | $data['title'], 171 | $data['author'], 172 | $data['link'], 173 | $data['description'], 174 | $data['imageUrl'], 175 | $data['fetchedAtUnix'], 176 | $data['imageBlob'] 177 | ); 178 | } 179 | } 180 | 181 | -------------------------------------------------------------------------------- /lib/Core/PodcastData/PodcastDataReader.php: -------------------------------------------------------------------------------- 1 | isLocalCacheAvailable()) { 25 | $this->cache = $cacheFactory->createLocal('GPodderSync-Podcasts'); 26 | } 27 | $this->httpClient = $httpClientService->newClient(); 28 | $this->subscriptionChangeRepository = $subscriptionChangeRepository; 29 | } 30 | 31 | public function getCachedOrFetchPodcastData(string $url, string $userId): ?PodcastData { 32 | if ($this->cache == null) { 33 | return $this->fetchPodcastData($url, $userId); 34 | } 35 | $oldData = $this->tryGetCachedPodcastData($url); 36 | if ($oldData) { 37 | return $oldData; 38 | } 39 | $newData = $this->fetchPodcastData($url, $userId); 40 | $this->trySetCachedPodcastData($url, $newData); 41 | return $newData; 42 | } 43 | 44 | private function userHasPodcast(string $url, string $userId): bool { 45 | $subscriptionChanges = $this->subscriptionChangeRepository->findByUrl($url, $userId); 46 | return $subscriptionChanges !== null; 47 | } 48 | 49 | public function fetchPodcastData(string $url, string $userId): ?PodcastData { 50 | if (!$this->userHasPodcast($url, $userId)) { 51 | return null; 52 | } 53 | $resp = $this->fetchUrl($url); 54 | $data = PodcastData::parseRssXml($resp->getBody()); 55 | $blob = $this->tryFetchImageBlob($data); 56 | if ($blob) { 57 | $data->setImageBlob($blob); 58 | } 59 | return $data; 60 | } 61 | 62 | private function tryFetchImageBlob(PodcastData $data): ?string { 63 | if (!$data->getImageUrl()) { 64 | return null; 65 | } 66 | try { 67 | $resp = $this->fetchUrl($data->getImageUrl()); 68 | $contentType = $resp->getHeader('Content-Type'); 69 | $body = $resp->getBody(); 70 | $bodyBase64 = base64_encode($body); 71 | return "data:$contentType;base64,$bodyBase64"; 72 | } catch (Exception $e) { 73 | return null; 74 | } 75 | } 76 | 77 | private function fetchUrl(string $url): IResponse { 78 | $resp = $this->httpClient->get($url); 79 | $statusCode = $resp->getStatusCode(); 80 | if ($statusCode < 200 || $statusCode >= 300) { 81 | throw new \ErrorException("Web request returned non-2xx status code: $statusCode"); 82 | } 83 | return $resp; 84 | } 85 | 86 | public function tryGetCachedPodcastData(string $url): ?PodcastData { 87 | $oldData = $this->cache->get($url); 88 | if (!$oldData) { 89 | return null; 90 | } 91 | return PodcastData::fromArray($oldData); 92 | } 93 | 94 | public function trySetCachedPodcastData(string $url, PodcastData $data): bool { 95 | return $this->cache->set($url, $data->toArray()); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /lib/Core/PodcastData/PodcastMetrics.php: -------------------------------------------------------------------------------- 1 | url = $url; 19 | $this->actionCounts = $actionCounts ?? new PodcastActionCounts; 20 | $this->listenedSeconds = $listenedSeconds; 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function getUrl(): string { 27 | return $this->url; 28 | } 29 | 30 | /** 31 | * @return PodcastActionCounts 32 | */ 33 | public function getActionCounts(): PodcastActionCounts { 34 | return $this->actionCounts; 35 | } 36 | 37 | /** 38 | * @return int 39 | */ 40 | public function getListenedSeconds(): int { 41 | return $this->listenedSeconds; 42 | } 43 | 44 | /** 45 | * @param int $seconds 46 | */ 47 | public function addListenedSeconds(int $seconds): void { 48 | $this->listenedSeconds += $seconds; 49 | } 50 | 51 | /** 52 | * @return array 53 | */ 54 | public function toArray(): array { 55 | return 56 | [ 57 | 'url' => $this->url, 58 | 'listenedSeconds' => $this->listenedSeconds, 59 | 'actionCounts' => $this->actionCounts->toArray(), 60 | ]; 61 | } 62 | 63 | /** 64 | * @return array 65 | */ 66 | public function jsonSerialize(): array { 67 | return $this->toArray(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /lib/Core/PodcastData/PodcastMetricsReader.php: -------------------------------------------------------------------------------- 1 | subscriptionChangeRepository = $subscriptionChangeRepository; 24 | $this->episodeActionRepository = $episodeActionRepository; 25 | } 26 | 27 | /** 28 | * @param string $userId 29 | * 30 | * @return PodcastMetrics[] 31 | */ 32 | public function metrics(string $userId): array { 33 | $episodeActions = $this->episodeActionRepository->findAll(0, $userId); 34 | 35 | $metricsPerUrl = array(); 36 | foreach ($episodeActions as $ep) { 37 | $url = $ep->getPodcast(); 38 | /** @var PodcastMetrics */ 39 | $metrics = $metricsPerUrl[$url] ?? $this->createMetricsForUrl($url); 40 | 41 | $actionLower = strtolower($ep->getAction()); 42 | $metrics->getActionCounts()->incrementAction($actionLower); 43 | 44 | if ($actionLower == 'play') { 45 | $seconds = $ep->getPosition(); 46 | if ($seconds && $seconds != -1) { 47 | $metrics->addListenedSeconds($seconds); 48 | } 49 | } 50 | 51 | $metricsPerUrl[$url] = $metrics; 52 | } 53 | 54 | $sinceDatetime = (new DateTime)->setTimestamp(0); 55 | $subscriptionChanges = $this->subscriptionChangeRepository->findAllSubscribed($sinceDatetime, $userId); 56 | /** @var PodcastMetrics[] */ 57 | $subscriptions = array_map(function (SubscriptionChangeEntity $sub) use ($metricsPerUrl) { 58 | $url = $sub->getUrl(); 59 | $metrics = $metricsPerUrl[$url] ?? $this->createMetricsForUrl($url); 60 | return $metrics; 61 | }, $subscriptionChanges); 62 | 63 | return $subscriptions; 64 | } 65 | 66 | private function createMetricsForUrl(string $url): PodcastMetrics { 67 | return new PodcastMetrics( 68 | $url, 69 | 0, 70 | new PodcastActionCounts() 71 | ); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /lib/Core/SubscriptionChange/SubscriptionChange.php: -------------------------------------------------------------------------------- 1 | url = $url; 15 | $this->isSubscribed = $isSubscribed; 16 | } 17 | 18 | /** 19 | * @return bool 20 | */ 21 | public function isSubscribed(): bool { 22 | return $this->isSubscribed; 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getUrl(): string { 29 | return $this->url; 30 | } 31 | 32 | public function __toString() : String { 33 | return $this->url; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/Core/SubscriptionChange/SubscriptionChangeRequestParser.php: -------------------------------------------------------------------------------- 1 | subscriptionChangeReader = $subscriptionChangeReader; 15 | } 16 | 17 | /** 18 | * @param array $urlsSubscribed 19 | * @param array $urlsUnsubscribed 20 | * 21 | * @return SubscriptionChange[] 22 | */ 23 | public function createSubscriptionChangeList(array $urlsSubscribed, array $urlsUnsubscribed): array { 24 | $urlsToSubscribe = $this->subscriptionChangeReader::mapToSubscriptionsChanges($urlsSubscribed, true); 25 | $urlsToDelete = $this->subscriptionChangeReader::mapToSubscriptionsChanges($urlsUnsubscribed, false); 26 | 27 | /** @var SubscriptionChange[] $subscriptionChanges */ 28 | return array_merge($urlsToSubscribe, $urlsToDelete); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/Core/SubscriptionChange/SubscriptionChangeSaver.php: -------------------------------------------------------------------------------- 1 | subscriptionChangeRepository = $subscriptionChangeRepository; 25 | $this->subscriptionChangeWriter = $subscriptionChangeWriter; 26 | $this->subscriptionChangeRequestParser = $subscriptionChangeRequestParser; 27 | } 28 | 29 | public function saveSubscriptionChanges(array $urlsSubscribed, array $urlsUnsubscribed, string $userId): void 30 | { 31 | $subscriptionChanges = $this->subscriptionChangeRequestParser->createSubscriptionChangeList($urlsSubscribed, $urlsUnsubscribed); 32 | foreach ($subscriptionChanges as $urlChangedSubscriptionStatus) { 33 | $subscriptionChangeEntity = new SubscriptionChangeEntity(); 34 | $subscriptionChangeEntity->setUrl($urlChangedSubscriptionStatus->getUrl()); 35 | $subscriptionChangeEntity->setSubscribed($urlChangedSubscriptionStatus->isSubscribed()); 36 | $subscriptionChangeEntity->setUpdated((new \DateTime())->format("Y-m-d\TH:i:s")); 37 | $subscriptionChangeEntity->setUserId($userId); 38 | 39 | try { 40 | $this->subscriptionChangeWriter->create($subscriptionChangeEntity); 41 | } catch (UniqueConstraintViolationException $uniqueConstraintViolationException) { 42 | $this->updateSubscription($subscriptionChangeEntity, $userId); 43 | } catch (Exception $exception) { 44 | if ($exception->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { 45 | $this->updateSubscription($subscriptionChangeEntity, $userId); 46 | } 47 | } 48 | } 49 | } 50 | 51 | /** 52 | * @param SubscriptionChangeEntity $subscriptionChangeEntity 53 | * @param string $userId 54 | * 55 | * @return void 56 | */ 57 | private function updateSubscription(SubscriptionChangeEntity $subscriptionChangeEntity, string $userId): void 58 | { 59 | $idEpisodeActionEntityToUpdate = $this->subscriptionChangeRepository->findByUrl($subscriptionChangeEntity->getUrl(), $userId)->getId(); 60 | $subscriptionChangeEntity->setId($idEpisodeActionEntityToUpdate); 61 | $this->subscriptionChangeWriter->update($subscriptionChangeEntity); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /lib/Core/SubscriptionChange/SubscriptionChangesReader.php: -------------------------------------------------------------------------------- 1 | addType('id','integer'); 44 | $this->addType('started','integer'); 45 | $this->addType('position','integer'); 46 | $this->addType('total','integer'); 47 | $this->addType('timestampEpoch','integer'); 48 | } 49 | 50 | public function jsonSerialize(): array { 51 | return [ 52 | 'id' => $this->id, 53 | 'podcast' => $this->podcast, 54 | 'episode' => $this->episode, 55 | 'guid' => $this->guid, 56 | 'action' => $this->action, 57 | 'position' => $this->position, 58 | 'started' => $this->started, 59 | 'total' => $this->total, 60 | 'timestamp' => $this->timestampEpoch, 61 | ]; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /lib/Db/EpisodeAction/EpisodeActionMapper.php: -------------------------------------------------------------------------------- 1 | db->getQueryBuilder(); 26 | 27 | $qb->select('*') 28 | ->from($this->getTableName()) 29 | ->where( 30 | $qb->expr()->gt('timestamp_epoch', $qb->createNamedParameter($sinceTimestamp, IQueryBuilder::PARAM_INT)) 31 | ) 32 | ->andWhere( 33 | $qb->expr()->eq('user_id', $qb->createNamedParameter($userId)) 34 | 35 | ); 36 | 37 | return $this->findEntities($qb); 38 | 39 | } 40 | 41 | /** 42 | * @param string $episodeIdentifier 43 | * @param string $userId 44 | * @return EpisodeActionEntity|null 45 | */ 46 | public function findByEpisodeUrl(string $episodeIdentifier, string $userId) : ?EpisodeActionEntity 47 | { 48 | $qb = $this->db->getQueryBuilder(); 49 | 50 | $qb->select('*') 51 | ->from($this->getTableName()) 52 | ->where( 53 | $qb->expr()->eq('episode', $qb->createNamedParameter($episodeIdentifier)) 54 | ) 55 | ->andWhere( 56 | $qb->expr()->eq('user_id', $qb->createNamedParameter($userId)) 57 | ); 58 | 59 | try { 60 | /** @var EpisodeActionEntity $episodeActionEntity */ 61 | return $this->findEntity($qb); 62 | } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { 63 | return null; 64 | } 65 | } 66 | 67 | public function findByGuid(string $guid, string $userId) : ?EpisodeActionEntity 68 | { 69 | $qb = $this->db->getQueryBuilder(); 70 | 71 | $qb->select('*') 72 | ->from($this->getTableName()) 73 | ->where( 74 | $qb->expr()->eq('guid', $qb->createNamedParameter($guid)) 75 | ) 76 | ->andWhere( 77 | $qb->expr()->eq('user_id', $qb->createNamedParameter($userId)) 78 | ); 79 | 80 | try { 81 | /** @var EpisodeActionEntity $episodeActionEntity */ 82 | return $this->findEntity($qb); 83 | } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { 84 | return null; 85 | } 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /lib/Db/EpisodeAction/EpisodeActionRepository.php: -------------------------------------------------------------------------------- 1 | episodeActionMapper = $episodeActionMapper; 16 | } 17 | 18 | /** 19 | * @param int $sinceEpoch 20 | * @param string $userId 21 | * 22 | * @return EpisodeAction[] 23 | */ 24 | public function findAll(int $sinceEpoch, string $userId): array 25 | { 26 | $episodeActions = []; 27 | foreach ( 28 | $this->episodeActionMapper->findAll($sinceEpoch, $userId) 29 | as $entity 30 | ) { 31 | $episodeActions[] = $this->mapEntityToEpisodeAction($entity); 32 | } 33 | return $episodeActions; 34 | } 35 | 36 | public function findByEpisodeUrl( 37 | string $episodeUrl, 38 | string $userId 39 | ): ?EpisodeAction { 40 | $episodeActionEntity = $this->episodeActionMapper->findByEpisodeUrl( 41 | $episodeUrl, 42 | $userId 43 | ); 44 | 45 | if ($episodeActionEntity === null) { 46 | return null; 47 | } 48 | 49 | return $this->mapEntityToEpisodeAction($episodeActionEntity); 50 | } 51 | 52 | public function findByGuid(string $guid, string $userId): ?EpisodeAction 53 | { 54 | $episodeActionEntity = $this->episodeActionMapper->findByGuid( 55 | $guid, 56 | $userId 57 | ); 58 | 59 | if ($episodeActionEntity === null) { 60 | return null; 61 | } 62 | 63 | return $this->mapEntityToEpisodeAction($episodeActionEntity); 64 | } 65 | 66 | public function deleteEpisodeActionByEpisodeUrl( 67 | string $episodeUrl, 68 | string $userId 69 | ): void { 70 | $episodeAction = $this->episodeActionMapper->findByEpisodeUrl( 71 | $episodeUrl, 72 | $userId 73 | ); 74 | $this->episodeActionMapper->delete($episodeAction); 75 | } 76 | 77 | private function mapEntityToEpisodeAction( 78 | EpisodeActionEntity $episodeActionEntity 79 | ): EpisodeAction { 80 | return new EpisodeAction( 81 | $episodeActionEntity->getPodcast(), 82 | $episodeActionEntity->getEpisode(), 83 | $episodeActionEntity->getAction(), 84 | DateTime::createFromFormat( 85 | "U", 86 | (string) $episodeActionEntity->getTimestampEpoch() 87 | )->format("c"), 88 | $episodeActionEntity->getStarted(), 89 | $episodeActionEntity->getPosition(), 90 | $episodeActionEntity->getTotal(), 91 | $episodeActionEntity->getGuid(), 92 | $episodeActionEntity->getId() 93 | ); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /lib/Db/EpisodeAction/EpisodeActionWriter.php: -------------------------------------------------------------------------------- 1 | episodeActionMapper = $episodeActionMapper; 17 | } 18 | 19 | /** 20 | * @throws Exception 21 | */ 22 | public function save(EpisodeActionEntity $episodeActionEntity): EpisodeActionEntity { 23 | return $this->episodeActionMapper->insert($episodeActionEntity); 24 | } 25 | 26 | /** 27 | * @throws Exception 28 | */ 29 | public function update(EpisodeActionEntity $episodeActionEntity) { 30 | return $this->episodeActionMapper->update($episodeActionEntity); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/Db/SubscriptionChange/SubscriptionChangeEntity.php: -------------------------------------------------------------------------------- 1 | addType('id','integer'); 18 | $this->addType('subscribed','boolean'); 19 | } 20 | 21 | /** 22 | * @return array 23 | */ 24 | public function jsonSerialize(): array { 25 | return [ 26 | 'id' => $this->id, 27 | 'url' => $this->url, 28 | 'subscribed' => $this->subscribed, 29 | 'updated' => $this->updated, 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Db/SubscriptionChange/SubscriptionChangeMapper.php: -------------------------------------------------------------------------------- 1 | db->getQueryBuilder(); 18 | 19 | $qb->select('*') 20 | ->from($this->getTableName()) 21 | ->where( 22 | $qb->expr()->eq('user_id', $qb->createNamedParameter($userId)) 23 | ); 24 | 25 | return $this->findEntities($qb); 26 | } 27 | 28 | public function findByUrl(string $url, string $userId): ?SubscriptionChangeEntity { 29 | $qb = $this->db->getQueryBuilder(); 30 | 31 | $qb->select('*') 32 | ->from($this->getTableName()) 33 | ->where( 34 | $qb->expr()->eq('url', $qb->createNamedParameter($url)) 35 | ) 36 | ->andWhere( 37 | $qb->expr()->eq('user_id', $qb->createNamedParameter($userId)) 38 | ); 39 | 40 | try { 41 | return $this->findEntity($qb); 42 | } catch (DoesNotExistException $e) { 43 | } catch (MultipleObjectsReturnedException $e) { 44 | } 45 | return null; 46 | } 47 | 48 | public function remove(SubscriptionChangeEntity $subscriptionChangeEntity) { 49 | $this->delete($subscriptionChangeEntity); 50 | } 51 | 52 | public function findAllSubscriptionState(bool $subscribed, \DateTime $sinceTimestamp, string $userId) { 53 | $qb = $this->db->getQueryBuilder(); 54 | 55 | $qb->select('url') 56 | ->from($this->getTableName()) 57 | ->where( 58 | $qb->expr()->eq('subscribed', $qb->createNamedParameter($subscribed, IQueryBuilder::PARAM_BOOL)) 59 | )->andWhere( 60 | $qb->expr()->gt('updated', $qb->createNamedParameter($sinceTimestamp, IQueryBuilder::PARAM_DATE)) 61 | ) 62 | ->andWhere( 63 | $qb->expr()->eq('user_id', $qb->createNamedParameter($userId)) 64 | ); 65 | 66 | return $this->findEntities($qb); 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /lib/Db/SubscriptionChange/SubscriptionChangeRepository.php: -------------------------------------------------------------------------------- 1 | subscriptionChangeMapper = $subscriptionChangeMapper; 15 | } 16 | 17 | public function findAll() : array { 18 | return $this->subscriptionChangeMapper->findAll(); 19 | } 20 | 21 | public function findByUrl(string $episode, string $userId): ?SubscriptionChangeEntity { 22 | return $this->subscriptionChangeMapper->findByUrl($episode, $userId); 23 | } 24 | 25 | public function findAllSubscribed(\DateTime $sinceTimestamp, string $userId) { 26 | return $this->subscriptionChangeMapper->findAllSubscriptionState(true, $sinceTimestamp, $userId); 27 | } 28 | 29 | public function findAllUnSubscribed(\DateTime $sinceTimestamp, string $userId) { 30 | return $this->subscriptionChangeMapper->findAllSubscriptionState(false, $sinceTimestamp, $userId); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Db/SubscriptionChange/SubscriptionChangeWriter.php: -------------------------------------------------------------------------------- 1 | subscriptionChangeMapper = $subscriptionChangeMapper; 16 | } 17 | 18 | 19 | public function purge() { 20 | foreach ($this->subscriptionChangeMapper->findAll() as $entity) { 21 | $this->subscriptionChangeMapper->delete($entity); 22 | } 23 | } 24 | 25 | public function create(SubscriptionChangeEntity $subscriptionChangeEntity): SubscriptionChangeEntity{ 26 | return $this->subscriptionChangeMapper->insert($subscriptionChangeEntity); 27 | } 28 | 29 | public function update(SubscriptionChangeEntity $subscriptionChangeEntity): SubscriptionChangeEntity{ 30 | return $this->subscriptionChangeMapper->update($subscriptionChangeEntity); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Migration/TimestampMigration.php: -------------------------------------------------------------------------------- 1 | db = $db; 17 | } 18 | 19 | /** 20 | * @inheritDoc 21 | */ 22 | public function getName(): string 23 | { 24 | return "Migrate timestamp values to integer to store unix epoch"; 25 | } 26 | 27 | /** 28 | * @inheritDoc 29 | */ 30 | public function run(IOutput $output) 31 | { 32 | $queryTimestamps = 33 | "SELECT id, timestamp FROM `*PREFIX*gpodder_episode_action` WHERE timestamp_epoch = 0"; 34 | $timestamps = $this->db->executeQuery($queryTimestamps)->fetchAll(); 35 | 36 | $result = 0; 37 | 38 | foreach ($timestamps as $timestamp) { 39 | $timestampEpoch = (new DateTime($timestamp["timestamp"]))->format( 40 | "U" 41 | ); 42 | $sql = 43 | "UPDATE `*PREFIX*gpodder_episode_action` " . 44 | "SET `timestamp_epoch` = " . 45 | $timestampEpoch . 46 | " " . 47 | "WHERE `id` = " . 48 | $timestamp["id"]; 49 | 50 | $result += $this->db->executeUpdate($sql); 51 | } 52 | 53 | return $result; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/Migration/Version0001Date20210520063113.php: -------------------------------------------------------------------------------- 1 | hasTable('gpodder_episode_action')) { 18 | $table = $schema->createTable('gpodder_episode_action'); 19 | $table->addColumn('id', 'integer', [ 20 | 'autoincrement' => true, 21 | 'notnull' => true, 22 | ]); 23 | $table->addColumn('podcast', 'string', [ 24 | 'notnull' => true, 25 | 'length' => 500 26 | ]); 27 | $table->addColumn('episode', 'string', [ 28 | 'notnull' => true, 29 | 'length' => 500, 30 | ]); 31 | $table->addColumn('action', 'string', [ 32 | 'notnull' => true, 33 | 'length' => 5 34 | ]); 35 | $table->addColumn('position', 'integer', [ 36 | 'notnull' => true, 37 | ]); 38 | 39 | $table->addColumn('started', Types::INTEGER, [ 40 | 'notnull' => true, 41 | ]); 42 | $table->addColumn('total', Types::INTEGER, [ 43 | 'notnull' => true, 44 | ]); 45 | $table->addColumn('timestamp', Types::DATETIME_MUTABLE, [ 46 | 'notnull' => true, 47 | ]); 48 | $table->addColumn('user_id', Types::STRING, [ 49 | 'notnull' => true, 50 | 'length' => 200, 51 | ]); 52 | 53 | $table->setPrimaryKey(['id']); 54 | $table->addUniqueIndex(['episode', 'user_id'], 'gpodder_episode_user_id'); 55 | } 56 | return $schema; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lib/Migration/Version0002Date20210524131313.php: -------------------------------------------------------------------------------- 1 | hasTable('gpodder_subscriptions')) { 17 | $table = $schema->createTable('gpodder_subscriptions'); 18 | $table->addColumn('id', 'integer', [ 19 | 'autoincrement' => true, 20 | 'notnull' => true, 21 | ]); 22 | $table->addColumn('url', Types::STRING, [ 23 | 'notnull' => true, 24 | 'length' => 500 25 | ]); 26 | 27 | $table->addColumn('subscribed', Types::BOOLEAN, [ 28 | 'notnull' => false, 29 | ]); 30 | 31 | $table->addColumn('updated', Types::DATETIME_MUTABLE, [ 32 | 'notnull' => true, 33 | ]); 34 | $table->addColumn('user_id', Types::STRING, [ 35 | 'notnull' => true, 36 | 'length' => 200, 37 | ]); 38 | 39 | $table->setPrimaryKey(['id']); 40 | $table->addUniqueIndex(['url', "user_id"], 'subscriptions_url_user'); 41 | 42 | } 43 | return $schema; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Migration/Version0003Date20210822231113.php: -------------------------------------------------------------------------------- 1 | getTable('gpodder_episode_action'); 17 | $table->changeColumn('action', ['length' => 10]); 18 | 19 | return $schema; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/Migration/Version0004Date20210823115513.php: -------------------------------------------------------------------------------- 1 | getTable('gpodder_episode_action'); 17 | $table->addColumn('guid', Types::STRING, [ 18 | 'length' => 500, 19 | 'notnull' => false 20 | ]); 21 | 22 | $table->addUniqueIndex(['guid', 'user_id'], 'gpodder_guid_user_id'); 23 | 24 | return $schema; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/Migration/Version0005Date20211004110900.php: -------------------------------------------------------------------------------- 1 | getTable('gpodder_episode_action'); 18 | $table->changeColumn('timestamp', ['notnull' => false]); 19 | $table->addColumn('timestamp_epoch', Types::INTEGER, [ 20 | 'notnull' => false, 21 | 'default' => 0, 22 | 'unsigned' => true, 23 | ]); 24 | 25 | return $schema; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/Migration/Version0006Date20221106215500.php: -------------------------------------------------------------------------------- 1 | getTable('gpodder_subscriptions'); 17 | 18 | // hotfix due to errors with too long key lengths (https://github.com/thrillfall/nextcloud-gpodder/issues/103) 19 | $table->dropIndex('subscriptions_url_user'); 20 | $table->addUniqueIndex(['url', "user_id"], 'subscriptions_url_user', [ 21 | 'lengths' => [ 500, 200 ] 22 | ]); 23 | 24 | $table->changeColumn('url', ['length' => 1000]); 25 | 26 | return $schema; 27 | } 28 | } -------------------------------------------------------------------------------- /lib/Migration/Version0007Date202211111100.php: -------------------------------------------------------------------------------- 1 | getTable('gpodder_subscriptions'); 16 | $table->dropIndex('subscriptions_url_user'); 17 | $table->addUniqueIndex(['url', "user_id"], 'subscriptions_url_user', [ 18 | 'lengths' => [ 500, 200 ] 19 | ]); 20 | 21 | return $schema; 22 | } 23 | } -------------------------------------------------------------------------------- /lib/Sections/GPodderSyncPersonal.php: -------------------------------------------------------------------------------- 1 | l = $l; 14 | $this->urlGenerator = $urlGenerator; 15 | } 16 | 17 | public function getIcon(): string { 18 | return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg'); 19 | } 20 | 21 | public function getID(): string { 22 | return 'gpoddersync'; 23 | } 24 | 25 | public function getName(): string { 26 | return $this->l->t('GPodder Sync'); 27 | } 28 | 29 | public function getPriority(): int { 30 | return 198; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Settings/GPodderSyncPersonal.php: -------------------------------------------------------------------------------- 1 | ", 6 | "contributors": [ 7 | "Kalle Fagerberg " 8 | ], 9 | "bugs": { 10 | "url": "https://github.com/thrillfall/nextcloud-gpodder/issues" 11 | }, 12 | "repository": { 13 | "url": "https://github.com/thrillfall/nextcloud-gpodder", 14 | "type": "git" 15 | }, 16 | "homepage": "https://github.com/thrillfall/nextcloud-gpodder", 17 | "private": true, 18 | "scripts": { 19 | "build": "webpack --node-env production --progress", 20 | "dev": "webpack --node-env development --progress", 21 | "watch": "webpack --node-env development --progress --watch", 22 | "serve": "webpack --node-env development serve --progress", 23 | "lint": "eslint --ext .js,.vue src", 24 | "lint:fix": "eslint --ext .js,.vue src --fix", 25 | "stylelint": "stylelint css/*.css css/*.scss src/**/*.scss src/**/*.vue", 26 | "stylelint:fix": "stylelint css/*.css css/*.scss src/**/*.scss src/**/*.vue --fix" 27 | }, 28 | "dependencies": { 29 | "@nextcloud/axios": "^1.11.0", 30 | "@nextcloud/dialogs": "^3.2.0", 31 | "@nextcloud/router": "^2.0.0", 32 | "@nextcloud/vue": "^5.4.0", 33 | "vue": "^2.7.10", 34 | "vue-material-design-icons": "^5.1.2" 35 | }, 36 | "browserslist": [ 37 | "extends @nextcloud/browserslist-config" 38 | ], 39 | "engines": { 40 | "node": "^14.0.0", 41 | "npm": "^7.0.0" 42 | }, 43 | "devDependencies": { 44 | "@nextcloud/babel-config": "^1.0.0", 45 | "@nextcloud/browserslist-config": "^2.2.0", 46 | "@nextcloud/eslint-config": "^8.0.0", 47 | "@nextcloud/stylelint-config": "^2.1.2", 48 | "@nextcloud/webpack-vue-config": "^5.2.1" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/components/SubscriptionListItem.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 107 | 108 | 114 | -------------------------------------------------------------------------------- /src/personalSettings.js: -------------------------------------------------------------------------------- 1 | import { generateFilePath } from '@nextcloud/router' 2 | 3 | import Vue from 'vue' 4 | import PersonalSettingsPage from './views/PersonalSettingsPage.vue' 5 | 6 | // eslint-disable-next-line 7 | __webpack_public_path__ = generateFilePath(appName, '', 'js/') 8 | 9 | Vue.mixin({ methods: { t, n } }) 10 | 11 | // https://nextcloud-vue-components.netlify.app/#/Introduction 12 | Vue.prototype.OC = window.OC 13 | Vue.prototype.OCA = window.OCA 14 | 15 | export default new Vue({ 16 | el: '#personal_settings', 17 | render: h => h(PersonalSettingsPage), 18 | }) 19 | -------------------------------------------------------------------------------- /src/views/PersonalSettingsPage.vue: -------------------------------------------------------------------------------- 1 | 38 | 39 | 95 | 96 | 102 | -------------------------------------------------------------------------------- /stylelint.config.js: -------------------------------------------------------------------------------- 1 | const stylelintConfig = require('@nextcloud/stylelint-config') 2 | 3 | module.exports = stylelintConfig 4 | -------------------------------------------------------------------------------- /templates/settings/personal.php: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 | -------------------------------------------------------------------------------- /tests/Helper/DatabaseTransaction.php: -------------------------------------------------------------------------------- 1 | get(IDBConnection::class); 13 | 14 | $db->beginTransaction(); 15 | } 16 | 17 | public function rollbackTransaction() { 18 | /* @var $db IDBConnection */ 19 | $db = OC::$server->get(IDBConnection::class); 20 | 21 | $db->rollBack(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/Helper/Writer/TestWriter.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 22 | } 23 | 24 | public function testAppInstalled() { 25 | $appManager = $this->container->query('OCP\App\IAppManager'); 26 | $this->assertTrue($appManager->isInstalled('gpoddersync')); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /tests/Integration/Controller/EpisodeActionControllerTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 33 | $this->db = \OC::$server->getDatabaseConnection(); 34 | } 35 | 36 | /** 37 | * @before 38 | */ 39 | public function before() 40 | { 41 | $this->startTransaction(); 42 | } 43 | 44 | public function testEpisodeActionListAction() 45 | { 46 | $userId = uniqid("test_user"); 47 | $episodeActionController = new EpisodeActionController( 48 | "gpoddersync", 49 | $this->createMock(IRequest::class), 50 | $userId, 51 | $this->container->get(EpisodeActionRepository::class), 52 | $this->container->get(EpisodeActionSaver::class) 53 | ); 54 | 55 | /** @var EpisodeActionWriter $episodeActionWriter */ 56 | $episodeActionWriter = $this->container->get( 57 | EpisodeActionWriter::class 58 | ); 59 | 60 | $mark = 1633520363; 61 | $episodeActionEntity = new EpisodeActionEntity(); 62 | $expectedPodcast = uniqid("test"); 63 | $episodeActionEntity->setPodcast($expectedPodcast); 64 | $expectedEpisode = uniqid("test"); 65 | $episodeActionEntity->setEpisode($expectedEpisode); 66 | $episodeActionEntity->setAction("PLAY"); 67 | $episodeActionEntity->setPosition(5); 68 | $episodeActionEntity->setStarted(0); 69 | $episodeActionEntity->setTotal(123); 70 | $episodeActionEntity->setTimestampEpoch($mark + 600); 71 | $episodeActionEntity->setUserId($userId); 72 | $episodeActionEntity->setGuid(self::TEST_GUID); 73 | $episodeActionWriter->save($episodeActionEntity); 74 | 75 | $response = $episodeActionController->list($mark); 76 | self::assertCount(1, $response->getData()["actions"]); 77 | 78 | $episodeActionInResponse = $response->getData()["actions"][0]; 79 | self::assertSame( 80 | "2021-10-06T11:49:23+00:00", 81 | $episodeActionInResponse["timestamp"] 82 | ); 83 | self::assertSame($expectedEpisode, $episodeActionInResponse["episode"]); 84 | self::assertSame($expectedPodcast, $episodeActionInResponse["podcast"]); 85 | self::assertSame(self::TEST_GUID, $episodeActionInResponse["guid"]); 86 | self::assertSame(5, $episodeActionInResponse["position"]); 87 | self::assertSame(0, $episodeActionInResponse["started"]); 88 | self::assertSame(123, $episodeActionInResponse["total"]); 89 | self::assertSame("PLAY", $episodeActionInResponse["action"]); 90 | } 91 | 92 | public function testEpisodeActionListWithoutSinceAction() 93 | { 94 | $userId = uniqid("test_user"); 95 | $episodeActionController = new EpisodeActionController( 96 | "gpoddersync", 97 | $this->createMock(IRequest::class), 98 | $userId, 99 | $this->container->get(EpisodeActionRepository::class), 100 | $this->container->get(EpisodeActionSaver::class) 101 | ); 102 | 103 | /** @var EpisodeActionWriter $episodeActionWriter */ 104 | $episodeActionWriter = $this->container->get( 105 | EpisodeActionWriter::class 106 | ); 107 | 108 | $episodeActionEntity = new EpisodeActionEntity(); 109 | $expectedPodcast = uniqid("test"); 110 | $episodeActionEntity->setPodcast($expectedPodcast); 111 | $expectedEpisode = uniqid("test"); 112 | $episodeActionEntity->setEpisode($expectedEpisode); 113 | $episodeActionEntity->setAction("PLAY"); 114 | $episodeActionEntity->setPosition(5); 115 | $episodeActionEntity->setStarted(0); 116 | $episodeActionEntity->setTotal(123); 117 | $episodeActionEntity->setTimestampEpoch(1633520363); 118 | $episodeActionEntity->setUserId($userId); 119 | $episodeActionEntity->setGuid(self::TEST_GUID); 120 | $episodeActionWriter->save($episodeActionEntity); 121 | 122 | $response = $episodeActionController->list(); 123 | self::assertCount(1, $response->getData()["actions"]); 124 | 125 | $episodeActionInResponse = $response->getData()["actions"][0]; 126 | self::assertSame( 127 | "2021-10-06T11:39:23+00:00", 128 | $episodeActionInResponse["timestamp"] 129 | ); 130 | self::assertSame($expectedEpisode, $episodeActionInResponse["episode"]); 131 | self::assertSame($expectedPodcast, $episodeActionInResponse["podcast"]); 132 | self::assertSame(self::TEST_GUID, $episodeActionInResponse["guid"]); 133 | self::assertSame(5, $episodeActionInResponse["position"]); 134 | self::assertSame(0, $episodeActionInResponse["started"]); 135 | self::assertSame(123, $episodeActionInResponse["total"]); 136 | self::assertSame("PLAY", $episodeActionInResponse["action"]); 137 | } 138 | 139 | public function testEpisodeActionCreateAction(): void 140 | { 141 | $time = time(); 142 | $userId = uniqid("test_user", true); 143 | $payload = json_decode( 144 | '[ 145 | { 146 | "podcast": "https://example.com/feed.rss", 147 | "episode": "https://example.com/files/s01e20.mp3", 148 | "guid": "s01e20-example-org", 149 | "action": "PLAY", 150 | "timestamp": "2009-12-12T09:00:00", 151 | "started": 15, 152 | "position": 120, 153 | "total": 500 154 | } 155 | ]', 156 | true, 157 | 512, 158 | JSON_THROW_ON_ERROR 159 | ); 160 | $request = $this->createMock(IRequest::class); 161 | $request 162 | ->expects($this->once()) 163 | ->method("getParams") 164 | ->will($this->returnValue($payload)); 165 | $episodeActionController = new EpisodeActionController( 166 | "gpoddersync", 167 | $request, 168 | $userId, 169 | $this->container->get(EpisodeActionRepository::class), 170 | $this->container->get(EpisodeActionSaver::class) 171 | ); 172 | $response = $episodeActionController->create(); 173 | 174 | $this->assertArrayHasKey("timestamp", $response->getData()); 175 | $this->assertGreaterThanOrEqual( 176 | $time, 177 | $response->getData()["timestamp"] 178 | ); 179 | /** @var EpisodeActionMapper $mapper */ 180 | $mapper = $this->container->query(EpisodeActionMapper::class); 181 | $episodeActionEntities = $mapper->findAll(0, $userId); 182 | /** @var EpisodeActionEntity $firstEntity */ 183 | $firstEntity = $episodeActionEntities[0]; 184 | $this->assertSame( 185 | "https://example.com/feed.rss", 186 | $firstEntity->getPodcast() 187 | ); 188 | $this->assertSame( 189 | "https://example.com/files/s01e20.mp3", 190 | $firstEntity->getEpisode() 191 | ); 192 | $this->assertSame("s01e20-example-org", $firstEntity->getGuid()); 193 | $this->assertSame("PLAY", $firstEntity->getAction()); 194 | $this->assertSame(120, $firstEntity->getPosition()); 195 | $this->assertSame(15, $firstEntity->getStarted()); 196 | $this->assertSame(1260608400, $firstEntity->getTimestampEpoch()); 197 | } 198 | 199 | /** 200 | * @after 201 | */ 202 | public function after(): void 203 | { 204 | $this->rollbackTransaction(); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /tests/Integration/Controller/SubscriptionChangeControllerTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 36 | $this->db = \OC::$server->getDatabaseConnection(); 37 | } 38 | 39 | /** 40 | * @before 41 | */ 42 | public function before() 43 | { 44 | $this->startTransaction(); 45 | } 46 | 47 | public function testSubscriptionChangeListAction() 48 | { 49 | $userId = uniqid("test_user"); 50 | $subscriptionChangeController = new SubscriptionChangeController( 51 | "gpoddersync", 52 | $this->createMock(IRequest::class), 53 | $userId, 54 | $this->container->get(SubscriptionChangeSaver::class), 55 | $this->container->get(SubscriptionChangeRepository::class) 56 | ); 57 | 58 | /** @var SubscriptionChangeWriter $subscriptionChangeWriter*/ 59 | $subscriptionChangeWriter = $this->container->get(SubscriptionChangeWriter::class); 60 | 61 | $mark = 1633520363; 62 | $subscriptionChangeEntity = new SubscriptionChangeEntity(); 63 | $expectedUrl1 = uniqid("test"); 64 | $subscriptionChangeEntity->setUrl($expectedUrl1); 65 | $subscriptionChangeEntity->setSubscribed(true); 66 | $subscriptionChangeEntity->setUpdated(date("Y-m-d\TH:i:s", $mark+600)); 67 | $subscriptionChangeEntity->setUserId($userId); 68 | 69 | $subscriptionChangeWriter->create($subscriptionChangeEntity); 70 | 71 | $subscriptionChangeEntity = new SubscriptionChangeEntity(); 72 | $expectedUrl2 = uniqid("test"); 73 | $subscriptionChangeEntity->setUrl($expectedUrl2); 74 | $subscriptionChangeEntity->setSubscribed(false); 75 | $subscriptionChangeEntity->setUpdated(date("Y-m-d\TH:i:s", $mark+1200)); 76 | $subscriptionChangeEntity->setUserId($userId); 77 | 78 | $subscriptionChangeWriter->create($subscriptionChangeEntity); 79 | 80 | $response = $subscriptionChangeController->list($mark); 81 | self::assertCount(1, $response->getData()['add']); 82 | self::assertCount(1, $response->getData()['remove']); 83 | 84 | $subscriptionChangeInResponse1 = $response->getData()['add'][0]; 85 | $subscriptionChangeInResponse2 = $response->getData()['remove'][0]; 86 | self::assertSame($expectedUrl1, $subscriptionChangeInResponse1); 87 | self::assertSame($expectedUrl2, $subscriptionChangeInResponse2); 88 | } 89 | 90 | public function testSubscriptionChangeListWithoutSinceAction() 91 | { 92 | $userId = uniqid("test_user"); 93 | $subscriptionChangeController = new SubscriptionChangeController( 94 | "gpoddersync", 95 | $this->createMock(IRequest::class), 96 | $userId, 97 | $this->container->get(SubscriptionChangeSaver::class), 98 | $this->container->get(SubscriptionChangeRepository::class) 99 | ); 100 | 101 | /** @var SubscriptionChangeWriter $subscriptionChangeWriter*/ 102 | $subscriptionChangeWriter = $this->container->get(SubscriptionChangeWriter::class); 103 | 104 | $subscriptionChangeEntity = new SubscriptionChangeEntity(); 105 | $expectedUrl1 = uniqid("test"); 106 | $subscriptionChangeEntity->setUrl($expectedUrl1); 107 | $subscriptionChangeEntity->setSubscribed(true); 108 | $subscriptionChangeEntity->setUpdated("2021-10-06T11:39:23"); 109 | $subscriptionChangeEntity->setUserId($userId); 110 | 111 | $subscriptionChangeWriter->create($subscriptionChangeEntity); 112 | 113 | $subscriptionChangeEntity = new SubscriptionChangeEntity(); 114 | $expectedUrl2 = uniqid("test"); 115 | $subscriptionChangeEntity->setUrl($expectedUrl2); 116 | $subscriptionChangeEntity->setSubscribed(false); 117 | $subscriptionChangeEntity->setUpdated("2021-10-06T11:49:23"); 118 | $subscriptionChangeEntity->setUserId($userId); 119 | 120 | $subscriptionChangeWriter->create($subscriptionChangeEntity); 121 | 122 | $response = $subscriptionChangeController->list(); 123 | self::assertCount(1, $response->getData()['add']); 124 | self::assertCount(1, $response->getData()['remove']); 125 | 126 | $subscriptionChangeInResponse1 = $response->getData()['add'][0]; 127 | $subscriptionChangeInResponse2 = $response->getData()['remove'][0]; 128 | self::assertSame($expectedUrl1, $subscriptionChangeInResponse1); 129 | self::assertSame($expectedUrl2, $subscriptionChangeInResponse2); 130 | } 131 | 132 | public function testSubscriptionChangeCreateAction(): void { 133 | $time = time(); 134 | $userId = uniqid('test_user'); 135 | 136 | $subscriptionChangeController = new SubscriptionChangeController( 137 | "gpoddersync", 138 | $this->createMock(IRequest::class), 139 | $userId, 140 | $this->container->get(SubscriptionChangeSaver::class), 141 | $this->container->get(SubscriptionChangeRepository::class) 142 | ); 143 | 144 | $expectedAdd1 = "https://example.com/feed.rss"; 145 | $expectedAdd2 = "https://example.org/feed.xml"; 146 | $expectedRemove1 = "https://www.example.com/feed.rss"; 147 | $expectedRemove2 = "https://www.example.com/feed.xml"; 148 | 149 | $response = $subscriptionChangeController->create( 150 | [$expectedAdd1, $expectedAdd2], 151 | [$expectedRemove1,$expectedRemove2] 152 | ); 153 | 154 | $this->assertArrayHasKey('timestamp', $response->getData()); 155 | $this->assertGreaterThanOrEqual($time, $response->getData()['timestamp']); 156 | 157 | /** @var SubscriptionChangeMapper $mapper */ 158 | $mapper = $this->container->query(SubscriptionChangeMapper::class); 159 | $subscriptionChangeAddEntities = $mapper->findAllSubscriptionState(true, (new DateTime)->setTimestamp(0), $userId); 160 | $subscriptionChangeRemoveEntities = $mapper->findAllSubscriptionState(false, (new DateTime)->setTimestamp(0), $userId); 161 | 162 | $firstAdd = $subscriptionChangeAddEntities[0]->getUrl(); 163 | $secondAdd = $subscriptionChangeAddEntities[1]->getUrl(); 164 | $firstRemove = $subscriptionChangeRemoveEntities[0]->getUrl(); 165 | $secondRemove = $subscriptionChangeRemoveEntities[1]->getUrl(); 166 | 167 | $this->assertSame($expectedAdd1, $firstAdd); 168 | $this->assertSame($expectedAdd2, $secondAdd); 169 | $this->assertSame($expectedRemove1, $firstRemove); 170 | $this->assertSame($expectedRemove2, $secondRemove); 171 | 172 | } 173 | 174 | /** 175 | * @after 176 | */ 177 | public function after(): void { 178 | $this->rollbackTransaction(); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /tests/Integration/EpisodeActionGuidMigrationTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 33 | $this->episodeActionWriter = $this->container->get(EpisodeActionWriter::class); 34 | $this->episodeActionRepository = $this->container->get(EpisodeActionRepository::class); 35 | } 36 | 37 | /** 38 | * @before 39 | */ 40 | public function before() 41 | { 42 | $this->startTransaction(); 43 | } 44 | 45 | public function testCreateSameEpisodeActionTriggersUniqueConstraintViolationException() 46 | { 47 | self::expectExceptionMessageMatches( 48 | "/(unique constraint|Integrity constraint violation)/" 49 | ); 50 | 51 | $episodeActionEntity = new EpisodeActionEntity(); 52 | $episodeActionEntity->setPodcast("https://podcast_01.url"); 53 | $episodeActionEntity->setEpisode("https://episode_01.url"); 54 | $episodeActionEntity->setAction("PLAY"); 55 | $episodeActionEntity->setPosition(5); 56 | $episodeActionEntity->setStarted(0); 57 | $episodeActionEntity->setTotal(123); 58 | $episodeActionEntity->setTimestampEpoch(1629676736); 59 | $episodeActionEntity->setUserId(self::USER_ID_0); 60 | $this->episodeActionWriter->save($episodeActionEntity); 61 | 62 | //and save again 63 | $this->episodeActionWriter->save($episodeActionEntity); 64 | 65 | } 66 | 67 | public function testFindEpisodeActionByEpisodeUrlAndThenGuid() 68 | { 69 | $episodeActionEntity = new EpisodeActionEntity(); 70 | $episodeActionEntity->setPodcast("https://podcast_01.url"); 71 | $episodeActionEntity->setEpisode("https://episode_01.url"); 72 | $episodeActionEntity->setAction("PLAY"); 73 | $episodeActionEntity->setPosition(5); 74 | $episodeActionEntity->setStarted(0); 75 | $episodeActionEntity->setTotal(123); 76 | $episodeActionEntity->setTimestampEpoch(1629676736); 77 | $episodeActionEntity->setUserId(self::USER_ID_0); 78 | $savedEpisodeActionEntity = $this->episodeActionWriter->save($episodeActionEntity); 79 | 80 | self::assertSame( 81 | $savedEpisodeActionEntity->getId(), 82 | $this->episodeActionRepository->findByEpisodeUrl($episodeActionEntity->getEpisode(), self::USER_ID_0)->getId() 83 | ); 84 | 85 | //update same episode action again this time with guid 86 | 87 | $episodeActionEntityWithGuid = clone $episodeActionEntity; 88 | $episodeActionEntityWithGuid->setGuid("guid:dadsaf4f4v"); 89 | $savedEpisodeActionEntityWithGuid = $this->episodeActionWriter->update($episodeActionEntityWithGuid); 90 | 91 | self::assertSame( 92 | $savedEpisodeActionEntityWithGuid->getId(), 93 | $this->episodeActionRepository->findByEpisodeUrl($episodeActionEntityWithGuid->getEpisode(), self::USER_ID_0)->getId() 94 | ); 95 | 96 | self::assertSame( 97 | $savedEpisodeActionEntityWithGuid->getId(), 98 | $this->episodeActionRepository->findByGuid($episodeActionEntityWithGuid->getGuid(), self::USER_ID_0)->getId() 99 | ); 100 | 101 | } 102 | 103 | /** 104 | * @after 105 | */ 106 | public function after() 107 | { 108 | $this->rollbackTransaction(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tests/Integration/EpisodeActionRepositoryTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 22 | } 23 | 24 | public function testTimestampOutputIsUTCHumandReadable(): void 25 | { 26 | /** @var EpisodeActionSaver $episodeActionSaver */ 27 | $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); 28 | 29 | $episodeUrl = uniqid("test_https://dts.podtrac.com/"); 30 | 31 | $timestampHumanReadable = "2021-08-22T23:58:56+00:00"; 32 | $guid = uniqid("test_gid://art19-episode-locator/V0/Ktd"); 33 | 34 | $savedEpisodeActionEntity = $episodeActionSaver->saveEpisodeActions( 35 | [ 36 | [ 37 | "podcast" => 38 | "https://rss.art19.com/dr-death-s3-miracle-man", 39 | "episode" => $episodeUrl, 40 | "guid" => $guid, 41 | "action" => "PLAY", 42 | "timestamp" => "2021-08-22T23:58:56", 43 | "started" => 47, 44 | "position" => 54, 45 | "total" => 2252, 46 | ], 47 | ], 48 | self::USER_ID_0 49 | )[0]; 50 | 51 | self::assertSame( 52 | 1629676736, 53 | $savedEpisodeActionEntity->getTimestampEpoch() 54 | ); 55 | 56 | $timestampOutputFormatted = \DateTime::createFromFormat( 57 | "U", 58 | (string) $savedEpisodeActionEntity->getTimestampEpoch() 59 | ) 60 | ->setTimezone(new \DateTimeZone("UTC")) 61 | ->format("c"); 62 | self::assertSame($timestampHumanReadable, $timestampOutputFormatted); 63 | 64 | /** @var $episodeActionRepository EpisodeActionRepository */ 65 | $episodeActionRepository = $this->container->get( 66 | EpisodeActionRepository::class 67 | ); 68 | 69 | $retrievedEpisodeActionEntity = $episodeActionRepository->findByGuid( 70 | $guid, 71 | self::USER_ID_0 72 | ); 73 | self::assertSame( 74 | "2021-08-22T23:58:56+00:00", 75 | $retrievedEpisodeActionEntity->getTimestamp() 76 | ); 77 | } 78 | 79 | public function testTimestampsWithTimezones(): void 80 | { 81 | /** @var EpisodeActionSaver $episodeActionSaver */ 82 | $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); 83 | 84 | $podcast = "https://example.com/rss"; 85 | $episodeUrl = uniqid("test_https://dts.podtrac.com/"); 86 | $guid = uniqid("test_gid://art19-episode-locator/V0/Ktd"); 87 | 88 | $timestamps = [ 89 | ["2024-12-01T16:29:56", 1733070596], 90 | ["2024-12-01T16:29:56Z", 1733070596], 91 | ["2024-12-01T16:29:56+01", 1733066996], 92 | ["2024-12-01T16:29:56+00:00", 1733070596], 93 | ["2024-12-01T16:29:56+02:00", 1733063396], 94 | ]; 95 | 96 | foreach ($timestamps as [$str, $epoch]) { 97 | $savedEpisodeActionEntity = $episodeActionSaver->saveEpisodeActions( 98 | [ 99 | [ 100 | "podcast" => $podcast, 101 | "episode" => $episodeUrl, 102 | "guid" => $guid, 103 | "action" => "PLAY", 104 | "timestamp" => $str, 105 | "started" => 47, 106 | "position" => 54, 107 | "total" => 2252, 108 | ], 109 | ], 110 | self::USER_ID_0 111 | )[0]; 112 | 113 | self::assertSame( 114 | $epoch, 115 | $savedEpisodeActionEntity->getTimestampEpoch() 116 | ); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /tests/Integration/EpisodeActionSaverGuidBackwardCompatibilityTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 26 | } 27 | 28 | public function testUpdateWithoutGuidDoesNotNullGuid(): void 29 | { 30 | /** @var EpisodeActionSaver $episodeActionSaver */ 31 | $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); 32 | 33 | $episodeUrl = uniqid("test_https://dts.podtrac.com/redirect.mp3/chrt.fm/track"); 34 | $guid = uniqid("test_gid://art19-episode-locator/V0/Ktd"); 35 | 36 | $savedEpisodeActionEntity = $episodeActionSaver->saveEpisodeActions( 37 | [["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "guid" => $guid, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]], 38 | self::USER_ID_0 39 | )[0]; 40 | 41 | $savedEpisodeActionEntityWithoutGuidFromOldDevice = $episodeActionSaver->saveEpisodeActions( 42 | [["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]], 43 | self::USER_ID_0 44 | )[0]; 45 | 46 | self::assertSame($savedEpisodeActionEntity->getId(), $savedEpisodeActionEntityWithoutGuidFromOldDevice->getId()); 47 | self::assertNotNull($savedEpisodeActionEntityWithoutGuidFromOldDevice->getGuid()); 48 | } 49 | 50 | public function testDoNotFailToUpdateEpisodeActionByGuidIfThereIsAnotherWithTheSameValueForEpisodeUrl(): void 51 | { 52 | //arrange 53 | /** @var EpisodeActionSaver $episodeActionSaver */ 54 | $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); 55 | 56 | $url = uniqid("https://podcast-mp3.dradio.de/"); 57 | $urlWithParameter = $url . "?ref=never_know_if_ill_be_removed"; 58 | $guid1 = uniqid("quid1"); 59 | $guid2 = uniqid("quid2"); 60 | 61 | $podcastUrl = uniqid("https://podcast"); 62 | 63 | $episodeActionSaver->saveEpisodeActions( 64 | [["podcast" => $podcastUrl, "episode" => $url, "guid" => $guid2, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 100, "total" => 2252]], 65 | self::USER_ID_0 66 | )[0]; 67 | 68 | $episodeActionSaver->saveEpisodeActions( 69 | [["podcast" => $podcastUrl, "episode" => $urlWithParameter, "guid" => $guid1, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 101, "total" => 2252]], 70 | self::USER_ID_0 71 | )[0]; 72 | 73 | //act 74 | $episodeActionSaver->saveEpisodeActions( 75 | [["podcast" => $podcastUrl, "episode" => $urlWithParameter, "guid" => $guid1, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 102, "total" => 2252]], 76 | self::USER_ID_0 77 | )[0]; 78 | 79 | //assert 80 | /** @var EpisodeActionRepository $episodeActionRepository */ 81 | $episodeActionRepository = $this->container->get(EpisodeActionRepository::class); 82 | $this->assertSame(100, $episodeActionRepository->findByGuid($guid2, self::USER_ID_0)->getPosition()); 83 | 84 | //act 85 | $episodeActionSaver->saveEpisodeActions( 86 | [["podcast" => $podcastUrl, "episode" => $urlWithParameter, "guid" => $guid2, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 103, "total" => 2252]], 87 | self::USER_ID_0 88 | )[0]; 89 | 90 | //assert 91 | /** @var EpisodeActionRepository $episodeActionRepository */ 92 | $episodeActionRepository = $this->container->get(EpisodeActionRepository::class); 93 | $this->assertSame(103, $episodeActionRepository->findByGuid($guid2, self::USER_ID_0)->getPosition()); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /tests/Integration/EpisodeActionSaverGuidMigrationTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 24 | } 25 | 26 | public function testCreateEpisodeActionWithoutGuidThenCreateAgainWithGuid() : void 27 | { 28 | /** @var EpisodeActionSaver $episodeActionSaver */ 29 | $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); 30 | 31 | $episodeUrl = uniqid("test_https://dts.podtrac.com/redirect.mp3/chrt.fm/track"); 32 | $guid = uniqid("test_gid://art19-episode-locator/V0/Ktd"); 33 | 34 | $savedEpisodeActionEntityWithoutGuid = $episodeActionSaver->saveEpisodeActions( 35 | [["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]], 36 | self::USER_ID_0 37 | )[0]; 38 | 39 | $savedEpisodeActionEntityWithGuid = $episodeActionSaver->saveEpisodeActions( 40 | [["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "guid" => $guid, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]], 41 | self::USER_ID_0 42 | )[0]; 43 | 44 | self::assertSame($savedEpisodeActionEntityWithoutGuid->getId(), $savedEpisodeActionEntityWithGuid->getId()); 45 | } 46 | 47 | public function testCreateEpisodeActionWithGuidThenCreateAgainWithGuidButDifferentEpisodeUrl() : void 48 | { 49 | /** @var EpisodeActionSaver $episodeActionSaver */ 50 | $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); 51 | 52 | $episodeUrl = uniqid("test_https://dts.podtrac.com/redirect.mp3/chrt.fm/track"); 53 | $guid = uniqid("test_gid://art19-episode-locator/V0/Ktd"); 54 | 55 | $savedEpisodeActionEntity = $episodeActionSaver->saveEpisodeActions( 56 | [["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "guid" => $guid, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]], 57 | self::USER_ID_0 58 | )[0]; 59 | 60 | $savedEpisodeActionEntityWithDifferentEpisodeUrl = $episodeActionSaver->saveEpisodeActions( 61 | [["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl . "_different", "guid" => $guid, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]], 62 | self::USER_ID_0 63 | )[0]; 64 | 65 | self::assertSame($savedEpisodeActionEntity->getId(), $savedEpisodeActionEntityWithDifferentEpisodeUrl->getId()); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /tests/Integration/Migration/SubscriptionMigrationTest.php: -------------------------------------------------------------------------------- 1 | container = $app->getContainer(); 36 | $this->db = \OC::$server->getDatabaseConnection(); 37 | } 38 | 39 | /** 40 | * @before 41 | */ 42 | public function before() 43 | { 44 | $this->startTransaction(); 45 | } 46 | 47 | public function testCreateSubscriptionWithLongFeedURL() 48 | { 49 | $userId = uniqid("test_user"); 50 | $subscriptionChangeController = new SubscriptionChangeController( 51 | "gpoddersync", 52 | $this->createMock(IRequest::class), 53 | $userId, 54 | $this->container->get(SubscriptionChangeSaver::class), 55 | $this->container->get(SubscriptionChangeRepository::class) 56 | ); 57 | 58 | /** @var SubscriptionChangeWriter $subscriptionChangeWriter*/ 59 | $subscriptionChangeWriter = $this->container->get(SubscriptionChangeWriter::class); 60 | 61 | $mark = 1633520363; 62 | $subscriptionChangeEntity = new SubscriptionChangeEntity(); 63 | // feed with length of 999 characters 64 | $expectedUrl = "https://www.example.com/feed.rss?key=2d4851a4c6d7788e55e72d1865caa1e67f8d55b64f24ceaab519f9c31d03f4a52d5599008b889fb57aabb2ba19d052cd5c187311fb91ac4892891f5fba5cd6404d015d2cefb9f66c680a3c0ad1139a7d04c3029854ec5099bb7a45141f4a37c9e9db40e79e1eacc7f8e04b24ef90821ed6f6f6d822a856ea80fed6571788a539bea05f6bf2557a1850396efad52a24ed06e781c07983ae0c66b70d161e73ba332655de980b539dfb6520d94abbd54f4aa4640eacaaeb400d0801faa622d9eacfa3b7d6644cc22e4f7cf0d129536c3e76bfdccd5366dadf4a0efa034f08408094c3198fe5ec3d2ee1b13d1422418674d75d13e15ecb8b74929973cad00ba9bd4b31eaf9875eaaade75628fbcc94d6d035aa54b137b1a1bf7ba428b663a3555c43d27c079d4942000dd3088fd13bdf2cd9af34052ddfedc5561acf8100d1d7759b7981c6abcfcac097425a8289005a490aad99ead6f59fca3fea9b06ebdf238400895dc13adf0db7874e7fa06baf316f4fc63d911e3d2bdaff543d71362de271d295f8d86e4ede7c5a71cad7737aa6ab24fc54d2cba43f7fd35f8a195aee1a543fda67b5fd4a8ac99c4fb7f682bff3818be83df5bd41efaef6544caeefc218a2ef9f7d8a9da70846a64389d60cf131416fdee78fabe307aa7cdfc0c84b137097d94a"; 65 | $subscriptionChangeEntity->setUrl($expectedUrl); 66 | $subscriptionChangeEntity->setSubscribed(true); 67 | $subscriptionChangeEntity->setUpdated(date("Y-m-d\TH:i:s", $mark+600)); 68 | $subscriptionChangeEntity->setUserId($userId); 69 | 70 | $subscriptionChangeWriter->create($subscriptionChangeEntity); 71 | 72 | 73 | $response = $subscriptionChangeController->list($mark); 74 | self::assertCount(1, $response->getData()['add']); 75 | 76 | $subscriptionChangeInResponse = $response->getData()['add'][0]; 77 | self::assertSame($expectedUrl, $subscriptionChangeInResponse); 78 | self::assertSame(strlen($subscriptionChangeInResponse), 999); 79 | } 80 | 81 | /** 82 | * @after 83 | */ 84 | public function after(): void { 85 | $this->rollbackTransaction(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /tests/Integration/Migration/TimestampMigrationTest.php: -------------------------------------------------------------------------------- 1 | getContainer(); 38 | $this->episodeActionWriter = $container->get(EpisodeActionWriter::class); 39 | $this->episodeActionMapper = $container->get(EpisodeActionMapper::class); 40 | $this->dbConnection = $container->get(IDBConnection::class); 41 | $this->migrationConfig = $container->get(AllConfig::class ); 42 | } 43 | 44 | /** 45 | * @before 46 | */ 47 | public function before() 48 | { 49 | $this->startTransaction(); 50 | } 51 | 52 | public function testTimestampConversionRepairStep() 53 | { 54 | if (!$this->dbConnection->getDatabasePlatform() instanceof PostgreSQL100Platform) { 55 | self::markTestSkipped("This test only works on postgres"); 56 | } 57 | 58 | $scienceEpisodeActionEntity = new EpisodeActionEntity(); 59 | $scienceEpisodeActionEntity->setPodcast("https://podcast_01.url"); 60 | $scienceEpisodeActionEntity->setEpisode(uniqid("https://episode_01.url")); 61 | $scienceEpisodeActionEntity->setAction("PLAY"); 62 | $scienceEpisodeActionEntity->setPosition(5); 63 | $scienceEpisodeActionEntity->setStarted(0); 64 | $scienceEpisodeActionEntity->setTotal(123); 65 | $scienceEpisodeActionEntity->setTimestamp("2021-08-22T23:58:56"); 66 | $scienceEpisodeActionEntity->setUserId(self::ADMIN); 67 | $scienceEpisodeActionEntity->setGuid(uniqid("self::TEST_GUID_1234")); 68 | $this->episodeActionWriter->save($scienceEpisodeActionEntity); 69 | 70 | $trueCrimeEpisodeActionEntity = new EpisodeActionEntity(); 71 | $trueCrimeEpisodeActionEntity->setPodcast(uniqid("podcast")); 72 | $trueCrimeEpisodeActionEntity->setEpisode(uniqid("episode_url")); 73 | $trueCrimeEpisodeActionEntity->setAction("PLAY"); 74 | $trueCrimeEpisodeActionEntity->setPosition(5); 75 | $trueCrimeEpisodeActionEntity->setStarted(0); 76 | $trueCrimeEpisodeActionEntity->setTotal(123); 77 | $trueCrimeEpisodeActionEntity->setTimestamp("2021-10-22T12:00:00"); 78 | $trueCrimeEpisodeActionEntity->setUserId(self::ADMIN); 79 | $trueCrimeEpisodeActionEntity->setGuid(uniqid("self::TEST_GUID_1234")); 80 | $this->episodeActionWriter->save($trueCrimeEpisodeActionEntity); 81 | 82 | $episodeActionBeforeConversion = $this->episodeActionMapper->findByGuid( 83 | $scienceEpisodeActionEntity->getGuid(), 84 | self::ADMIN 85 | ); 86 | 87 | $this->assertEquals( 88 | 0, 89 | $episodeActionBeforeConversion->getTimestampEpoch() 90 | ); 91 | 92 | $timestampMigration = new TimestampMigration($this->dbConnection, $this->migrationConfig); 93 | $timestampMigration->run($this->createMock(SimpleOutput::class)); 94 | 95 | $scienceEpisodeActionAfterConversion = $this->episodeActionMapper->findByGuid( 96 | $scienceEpisodeActionEntity->getGuid(), 97 | self::ADMIN 98 | ); 99 | $this->assertSame( 100 | 1629676736, 101 | $scienceEpisodeActionAfterConversion->getTimestampEpoch() 102 | ); 103 | 104 | $trueCrimeEpisodeActionAfterConversion = $this->episodeActionMapper->findByGuid( 105 | $trueCrimeEpisodeActionEntity->getGuid(), 106 | self::ADMIN 107 | ); 108 | $this->assertSame( 109 | 1634904000, 110 | $trueCrimeEpisodeActionAfterConversion->getTimestampEpoch() 111 | ); 112 | } 113 | 114 | /** 115 | * @after 116 | */ 117 | public function after() 118 | { 119 | $this->rollbackTransaction(); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /tests/Unit/Core/EpisodeAction/EpisodeActionReaderTest.php: -------------------------------------------------------------------------------- 1 | fromArray([["podcast" => "https://example.org/feed.xml", "episode" => "https://example.org/episode1.mp3", "action" => "PLAY", "timestamp" => "2021-10-03T12:03:17", "started" => 0, "position" => 50, "total"=> 3422]]); 13 | 14 | $this->assertSame("https://example.org/feed.xml", $episodeActions[0]->getPodcast()); 15 | $this->assertSame("https://example.org/episode1.mp3", $episodeActions[0]->getEpisode()); 16 | $this->assertSame("PLAY", $episodeActions[0]->getAction()); 17 | $this->assertSame("2021-10-03T12:03:17", $episodeActions[0]->getTimestamp()); 18 | $this->assertSame(0, $episodeActions[0]->getStarted()); 19 | $this->assertSame(50, $episodeActions[0]->getPosition()); 20 | $this->assertSame(3422, $episodeActions[0]->getTotal()); 21 | } 22 | 23 | public function testCreateFromMultipleEpisodesArray(): void { 24 | $reader = new EpisodeActionReader(); 25 | $episodeActions = $reader->fromArray([ 26 | ["podcast" => "https://example.org/feed.xml", "episode" => "https://example.org/episode1.mp3", "guid" => "episode1", "action" => "PLAY", "timestamp" => "2021-10-03T12:03:17", "started" => 0, "position" => 50, "total"=> 3422], 27 | ["podcast" => "https://example.org/feed.xml", "episode" => "https://example.org/episode2.mp3", "guid" => "episode2", "action" => "download", "timestamp" => "2021-10-03T12:03:17"], 28 | ["podcast" => "https://example.com/feed.xml", "episode" => "https://chrt.fm/track/47G541/injector.simplecastaudio.com/f16c3da7-cf46-4a42-99b7-8467255c6086/episodes/e8e24c01-6157-40e8-9b5a-45d539aeb7e6/audio/128/default.mp3?aid=rss_feed&awCollectionId=f16c3da7-cf46-4a42-99b7-8467255c6086&awEpisodeId=e8e24c01-6157-40e8-9b5a-45d539aeb7e6&feed=wEl4UUJZ", "guid" => "EPISODE-001-EXAMPLE-COM", "action" => "PLAY", "timestamp" => "2021-10-03T12:03:17", "started" => 50, "position" => 221, "total"=> 450] 29 | ]); 30 | 31 | $this->assertSame("https://example.org/feed.xml", $episodeActions[0]->getPodcast()); 32 | $this->assertSame("https://example.org/episode1.mp3", $episodeActions[0]->getEpisode()); 33 | $this->assertSame("episode1", $episodeActions[0]->getGuid()); 34 | $this->assertSame("PLAY", $episodeActions[0]->getAction()); 35 | $this->assertSame("2021-10-03T12:03:17", $episodeActions[0]->getTimestamp()); 36 | $this->assertSame(0, $episodeActions[0]->getStarted()); 37 | $this->assertSame(50, $episodeActions[0]->getPosition()); 38 | $this->assertSame(3422, $episodeActions[0]->getTotal()); 39 | 40 | $this->assertSame("https://example.org/feed.xml", $episodeActions[1]->getPodcast()); 41 | $this->assertSame("https://example.org/episode2.mp3", $episodeActions[1]->getEpisode()); 42 | $this->assertSame("episode2", $episodeActions[1]->getGuid()); 43 | $this->assertSame("DOWNLOAD", $episodeActions[1]->getAction()); 44 | $this->assertSame("2021-10-03T12:03:17", $episodeActions[1]->getTimestamp()); 45 | $this->assertSame(-1, $episodeActions[1]->getStarted()); 46 | $this->assertSame(-1, $episodeActions[1]->getPosition()); 47 | $this->assertSame(-1, $episodeActions[1]->getTotal()); 48 | 49 | $this->assertSame("https://example.com/feed.xml", $episodeActions[2]->getPodcast()); 50 | $this->assertSame("https://chrt.fm/track/47G541/injector.simplecastaudio.com/f16c3da7-cf46-4a42-99b7-8467255c6086/episodes/e8e24c01-6157-40e8-9b5a-45d539aeb7e6/audio/128/default.mp3?aid=rss_feed&awCollectionId=f16c3da7-cf46-4a42-99b7-8467255c6086&awEpisodeId=e8e24c01-6157-40e8-9b5a-45d539aeb7e6&feed=wEl4UUJZ", $episodeActions[2]->getEpisode()); 51 | $this->assertSame("EPISODE-001-EXAMPLE-COM", $episodeActions[2]->getGuid()); 52 | $this->assertSame("PLAY", $episodeActions[2]->getAction()); 53 | $this->assertSame("2021-10-03T12:03:17", $episodeActions[2]->getTimestamp()); 54 | $this->assertSame(50, $episodeActions[2]->getStarted()); 55 | $this->assertSame(221, $episodeActions[2]->getPosition()); 56 | $this->assertSame(450, $episodeActions[2]->getTotal()); 57 | } 58 | 59 | public function testCreateWithFaultyData(): void { 60 | $this->expectException(\InvalidArgumentException::class); 61 | $this->expectExceptionMessage('Client sent incomplete or invalid data: {"podcast":"https:\/\/example.org\/feed.xml","action":"download","timestamp":"2021-10-03T12:03:17"}'); 62 | (new EpisodeActionReader())->fromArray([ 63 | ["podcast" => "https://example.org/feed.xml", "action" => "download", "timestamp" => "2021-10-03T12:03:17"], 64 | ["podcast" => "https://example.org/feed.xml", "episode" => "https://example.org/episode2.mp3", "guid" => "episode2", "action" => "download", "timestamp" => "2021-10-03T12:03:17"], 65 | ]); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /tests/Unit/Core/EpisodeAction/EpisodeActionTest.php: -------------------------------------------------------------------------------- 1 | 'podcast1', 14 | 'episode' => 'episode1', 15 | 'timestamp' => '2021-10-07T13:27:14', 16 | 'guid' => 'podcast1guid', 17 | 'position' => 120, 18 | 'started' => 15, 19 | 'total' => 500, 20 | 'action' => 'PLAY', 21 | ]; 22 | $this->assertSame($expected, $episodeAction->toArray()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Unit/Core/PodcastData/PodcastDataTest.php: -------------------------------------------------------------------------------- 1 | 'title1', 14 | 'author' => 'author1', 15 | 'link' => 'http://example.com/', 16 | 'description' => 'description1', 17 | 'imageUrl' => 'http://example.com/image.jpg', 18 | 'imageBlob' => null, 19 | 'fetchedAtUnix' => 1337, 20 | ]; 21 | $this->assertSame($expected, $podcastData->toArray()); 22 | } 23 | 24 | public function testFromArray(): void { 25 | $podcastData = new PodcastData('title1', 'author1', 'http://example.com/', 'description1', 'http://example.com/image.jpg', 1337); 26 | $expected = $podcastData->toArray(); 27 | $fromArray = PodcastData::fromArray($expected); 28 | $this->assertSame($expected, $fromArray->toArray()); 29 | } 30 | 31 | public function testParseRssXml(): void { 32 | $xml = ' 33 | 40 | 41 | The title of this Podcast 42 | All rights reserved 43 | http://example.com 44 | 45 | 46 | en-us 47 | Some long description 48 | The Podcast Author 49 | Some long description 50 | no 51 | 52 | nextcloud, gpodder 53 | 54 | Owner of the podcast 55 | editors@example.com 56 | 57 | 58 | 59 | 60 | Support our work 61 | thrillfall 62 | jilleJr 63 | 64 | 65 | '; 66 | 67 | $podcastData = PodcastData::parseRssXml($xml, 1337); 68 | $expected = [ 69 | 'title' => 'The title of this Podcast', 70 | 'author' => 'The Podcast Author', 71 | 'link' => 'http://example.com', 72 | 'description' => 'Some long description', 73 | 'imageUrl' => 'https://example.com/image.jpg', 74 | 'imageBlob' => null, 75 | 'fetchedAtUnix' => 1337, 76 | ]; 77 | $this->assertSame($expected, $podcastData->toArray()); 78 | } 79 | 80 | public function testParseRssXmlPartial(): void { 81 | $xml = ' 82 | 89 | 90 | The title of this Podcast 91 | All rights reserved 92 | http://example.com 93 | The Podcast Author 94 | 95 | Some image 96 | 97 | 98 | 99 | 100 | '; 101 | 102 | $podcastData = PodcastData::parseRssXml($xml, 1337); 103 | $expected = [ 104 | 'title' => 'The title of this Podcast', 105 | 'author' => 'The Podcast Author', 106 | 'link' => 'http://example.com', 107 | 'description' => null, 108 | 'imageUrl' => null, 109 | 'imageBlob' => null, 110 | 'fetchedAtUnix' => 1337, 111 | ]; 112 | $this->assertSame($expected, $podcastData->toArray()); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /tests/Unit/Core/SubscriptionChange/SubscriptionChangeReaderTest.php: -------------------------------------------------------------------------------- 1 | assertCount(2, $subscriptionChange); 13 | $this->assertSame("https://feeds.megaphone.fm/HSW8286374095", $subscriptionChange[0]->getUrl()); 14 | $this->assertSame("https://feeds.megaphone.fm/another", $subscriptionChange[1]->getUrl()); 15 | } 16 | 17 | 18 | public function testNonUrisAreOmmited(): void { 19 | $subscriptionChange = SubscriptionChangesReader::mapToSubscriptionsChanges([ 20 | "https://feeds.megaphone.fm/HSW8286374095", 21 | "antennapod_local:content://com.android.externalstorage.documents/tree/home:podcast" 22 | ], true); 23 | $this->assertCount(1, $subscriptionChange); 24 | $this->assertSame("https://feeds.megaphone.fm/HSW8286374095", $subscriptionChange[0]->getUrl()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Unit/Core/SubscriptionChange/SubscriptionChangeRequestParserTest.php: -------------------------------------------------------------------------------- 1 | createSubscriptionChangeList(["https://feeds.simplecast.com/54nAGcIl", "https://feeds.simplecast.com/another"],["https://i.am-removed/GcIl"]); 17 | $this->assertCount(3, $subscriptionChanges); 18 | $this->assertSame("https://feeds.simplecast.com/54nAGcIl", $subscriptionChanges[0]->getUrl()); 19 | $this->assertSame("https://feeds.simplecast.com/another", $subscriptionChanges[1]->getUrl()); 20 | $this->assertSame("https://i.am-removed/GcIl", $subscriptionChanges[2]->getUrl()); 21 | $this->assertTrue($subscriptionChanges[0]->isSubscribed()); 22 | $this->assertFalse($subscriptionChanges[2]->isSubscribed()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | addValidRoot(OC::$SERVERROOT . '/tests'); 12 | 13 | // Fix for "Autoload path not allowed: .../gpoddersync/tests/testcase.php" 14 | OC_App::loadApp('nextcloud-gpodder'); 15 | 16 | OC_Hook::clear(); 17 | -------------------------------------------------------------------------------- /tests/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ./Unit 5 | 6 | 7 | ./Integration 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const webpackConfig = require('@nextcloud/webpack-vue-config') 3 | 4 | webpackConfig.entry = { 5 | personalSettings: path.join(__dirname, 'src', 'personalSettings.js'), 6 | } 7 | 8 | module.exports = webpackConfig 9 | --------------------------------------------------------------------------------