Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Jan 20, 2021
2 parents 519dd17 + e1032ff commit bc399d9
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
discord:
name: Send Discord Notification
needs: build_and_push
if: always() && github.event_name != 'pull_request' && !contains(github.event.head_commit.message, '[skip ci]')
runs-on: ubuntu-20.04
steps:
- name: Get Build Job Status
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
test:
name: Lint & Test Build
runs-on: ubuntu-20.04
container: node:12.18-alpine
steps:
Expand Down Expand Up @@ -41,9 +42,61 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: npx semantic-release
build-snap:
name: Build Snap Package (${{ matrix.architecture }})
needs: semantic-release
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
architecture:
- amd64
- arm64
- armhf
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Prepare
id: prepare
run: |
git fetch --prune --unshallow --tags
if [[ $GITHUB_REF == refs/tags/* || $GITHUB_REF == refs/heads/master ]]; then
echo ::set-output name=RELEASE::stable
else
echo ::set-output name=RELEASE::edge
fi
- name: Set Up QEMU
uses: docker/setup-qemu-action@v1

- name: Build Snap Package
uses: diddlesnaps/snapcraft-multiarch-action@v1
id: build
with:
architecture: ${{ matrix.architecture }}

- name: Upload Snap Package
uses: actions/upload-artifact@v2
with:
name: overseerr-snap-package-${{ matrix.architecture }}
path: ${{ steps.build.outputs.snap }}

- name: Review Snap Package
uses: diddlesnaps/snapcraft-review-tools-action@v1
with:
snap: ${{ steps.build.outputs.snap }}

- name: Publish Snap Package
uses: snapcore/action-publish@v1
with:
store_login: ${{ secrets.SNAP_LOGIN }}
snap: ${{ steps.build.outputs.snap }}
release: ${{ steps.prepare.outputs.RELEASE }}
discord:
name: Send Discord Notification
needs: semantic-release
if: always()
runs-on: ubuntu-20.04
steps:
- name: Get Build Job Status
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Publish Snap
on:
push:
branches: [develop]
tags: [v*]
pull_request: ~

jobs:
test:
Expand Down Expand Up @@ -74,10 +72,10 @@ jobs:
store_login: ${{ secrets.SNAP_LOGIN }}
snap: ${{ steps.build.outputs.snap }}
release: ${{ steps.prepare.outputs.RELEASE }}

discord:
name: Send Discord Notification
needs: build-snap
if: always() && !contains(github.event.head_commit.message, '[skip ci]')
runs-on: ubuntu-20.04
steps:
- name: Get Build Job Status
Expand Down
45 changes: 37 additions & 8 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ export class MediaRequest {
logger.error('No parent media!', { label: 'Media Request' });
return;
}

if (media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE) {
logger.warn(
'Media became available before request was approved. Approval notification will be skipped.',
{ label: 'Media Request' }
);
return;
}

const tmdb = new TheMovieDb();
if (this.media.mediaType === MediaType.MOVIE) {
const movie = await tmdb.getMovie({ movieId: this.media.tmdbId });
Expand Down Expand Up @@ -205,7 +214,13 @@ export class MediaRequest {
return;
}
const seasonRequestRepository = getRepository(SeasonRequest);
if (this.status === MediaRequestStatus.APPROVED) {
if (
this.status === MediaRequestStatus.APPROVED &&
// Do not update the status if the item is already partially available or available
media[this.is4k ? 'status4k' : 'status'] !== MediaStatus.AVAILABLE &&
media[this.is4k ? 'status4k' : 'status'] !==
MediaStatus.PARTIALLY_AVAILABLE
) {
if (this.is4k) {
media.status4k = MediaStatus.PROCESSING;
} else {
Expand Down Expand Up @@ -358,6 +373,21 @@ export class MediaRequest {
});
const movie = await tmdb.getMovie({ movieId: this.media.tmdbId });

const media = await mediaRepository.findOne({
where: { id: this.media.id },
});

if (!media) {
logger.error('Media not present');
return;
}

if (
media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE
) {
throw new Error('Media already available');
}

// Run this asynchronously so we don't wait for it on the UI side
radarr
.addMovie({
Expand All @@ -373,13 +403,6 @@ export class MediaRequest {
})
.then(async (success) => {
if (!success) {
const media = await mediaRepository.findOne({
where: { id: this.media.id },
});
if (!media) {
logger.error('Media not present');
return;
}
media.status = MediaStatus.UNKNOWN;
await mediaRepository.save(media);
logger.warn(
Expand Down Expand Up @@ -464,6 +487,12 @@ export class MediaRequest {
throw new Error('Media data is missing');
}

if (
media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE
) {
throw new Error('Media already available');
}

const tmdb = new TheMovieDb();
const sonarr = new SonarrAPI({
apiKey: sonarrSettings.apiKey,
Expand Down
13 changes: 11 additions & 2 deletions server/routes/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ requestRoutes.post(
// (Unless there are no seasons, in which case we abort)
if (media.requests) {
existingSeasons = media.requests
.filter((request) => request.is4k === req.body.is4k)
.filter(
(request) =>
request.is4k === req.body.is4k &&
request.status !== MediaRequestStatus.DECLINED
)
.reduce((seasons, request) => {
const combinedSeasons = request.seasons.map(
(season) => season.seasonNumber
Expand Down Expand Up @@ -303,7 +307,12 @@ requestRoutes.put<{ requestId: string }>(

// Get all requested seasons that are not part of this request we are editing
const existingSeasons = media.requests
.filter((r) => r.is4k === request.is4k && r.id !== request.id)
.filter(
(r) =>
r.is4k === request.is4k &&
r.id !== request.id &&
r.status !== MediaRequestStatus.DECLINED
)
.reduce((seasons, r) => {
const combinedSeasons = r.seasons.map(
(season) => season.seasonNumber
Expand Down
34 changes: 33 additions & 1 deletion server/subscriber/MediaSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UpdateEvent,
} from 'typeorm';
import TheMovieDb from '../api/themoviedb';
import { MediaStatus, MediaType } from '../constants/media';
import { MediaRequestStatus, MediaStatus, MediaType } from '../constants/media';
import Media from '../entity/Media';
import { MediaRequest } from '../entity/MediaRequest';
import Season from '../entity/Season';
Expand Down Expand Up @@ -102,6 +102,24 @@ export class MediaSubscriber implements EntitySubscriberInterface {
}
}

private async updateChildRequestStatus(event: Media, is4k: boolean) {
const requestRepository = getRepository(MediaRequest);

const requests = await requestRepository.find({
where: { media: event.id },
});

for (const request of requests) {
if (
request.is4k === is4k &&
request.status === MediaRequestStatus.PENDING
) {
request.status = MediaRequestStatus.APPROVED;
await requestRepository.save(request);
}
}
}

public beforeUpdate(event: UpdateEvent<Media>): void {
if (!event.entity) {
return;
Expand All @@ -121,5 +139,19 @@ export class MediaSubscriber implements EntitySubscriberInterface {
) {
this.notifyAvailableSeries(event.entity, event.databaseEntity);
}

if (
event.entity.status === MediaStatus.AVAILABLE &&
event.databaseEntity.status === MediaStatus.PENDING
) {
this.updateChildRequestStatus(event.entity, false);
}

if (
event.entity.status4k === MediaStatus.AVAILABLE &&
event.databaseEntity.status4k === MediaStatus.PENDING
) {
this.updateChildRequestStatus(event.entity, true);
}
}
}
13 changes: 10 additions & 3 deletions src/components/RequestModal/TvRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ const TvRequestModal: React.FC<RequestModalProps> = ({

const getAllRequestedSeasons = (): number[] => {
const requestedSeasons = (data?.mediaInfo?.requests ?? [])
.filter((request) => request.is4k === is4k)
.filter(
(request) =>
request.is4k === is4k &&
request.status !== MediaRequestStatus.DECLINED
)
.reduce((requestedSeasons, request) => {
return [
...requestedSeasons,
Expand Down Expand Up @@ -255,8 +259,11 @@ const TvRequestModal: React.FC<RequestModalProps> = ({

if (
data?.mediaInfo &&
(data.mediaInfo.requests || []).filter((request) => request.is4k === is4k)
.length > 0
(data.mediaInfo.requests || []).filter(
(request) =>
request.is4k === is4k &&
request.status !== MediaRequestStatus.DECLINED
).length > 0
) {
data.mediaInfo.requests
.filter((request) => request.is4k === is4k)
Expand Down

0 comments on commit bc399d9

Please sign in to comment.