Skip to content

Commit

Permalink
feat(Video): Group videos into year folder
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Previously all videos were in the videos folder, now per year
  • Loading branch information
danactive committed Feb 20, 2021
1 parent 2e837bc commit 92a11d1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
13 changes: 9 additions & 4 deletions ui/app/containers/InfiniteThumbs/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ export const argsPhotoXmlPath = ({ gallery, filename }) => {
};

export const argsVideoXmlPath = ({ gallery, filename }) => ({
path: `/galleries/${gallery}/media/videos/${filename}`,
path: `/galleries/${gallery}/media/videos/${getYear(filename)}/${filename}`,
});

export const replaceThumbToVideo = (thumbLink, videoFilename) => {
const paths = thumbLink.replace('thumbs', 'videos').split('/');
const pathsWithoutThumb = paths.slice(0, 8); // delete thumb JPG path
const videoLink = `${pathsWithoutThumb.join('/')}/${videoFilename}`;
return videoLink;
};

// saga WORKER for CHOOSE_MEMORY for Dropbox gallery
export function* getPhotoPathsOnDropbox({
memory,
Expand Down Expand Up @@ -117,9 +124,7 @@ export function* getPhotoPathsOnCdn({
}),
);

const paths = memory.thumbLink.replace('thumbs', 'videos').split('/');
paths.splice(7, 2); // delete year folder and JPG
const videoLink = `${paths.join('/')}/${memory.filename}`;
const videoLink = replaceThumbToVideo(memory.thumbLink, memory.filename);
yield put(
loadVideoSuccess({
id,
Expand Down
45 changes: 44 additions & 1 deletion ui/app/containers/InfiniteThumbs/tests/saga.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
import { determineAdjacentInCarousel } from '../saga';
import {
determineAdjacentInCarousel,
argsPhotoXmlPath,
argsVideoXmlPath,
replaceThumbToVideo,
} from '../saga';

/* eslint-disable default-case, no-param-reassign */
describe('InfiniteThumbs Saga', () => {
describe('argsPhotoXmlPath', () => {
test('JPG', () => {
const gallery = 'demo';
const filename = '2021-02-20-50.jpg';
const expected = {
path: '/galleries/demo/media/photos/2021/2021-02-20-50.jpg',
};
expect(argsPhotoXmlPath({ gallery, filename })).toEqual(expected);
});

test('Video', () => {
const gallery = 'demo';
const filename = '2021-02-20-50.mp4';
const expected = {
path: '/galleries/demo/media/photos/2021/2021-02-20-50.jpg',
};
expect(argsPhotoXmlPath({ gallery, filename })).toEqual(expected);
});
});

describe('Video paths', () => {
test('argsVideoXmlPath', () => {
const gallery = 'demo';
const filename = '2021-02-20-50.mp4';
const expected = {
path: '/galleries/demo/media/videos/2021/2021-02-20-50.mp4',
};
expect(argsVideoXmlPath({ gallery, filename })).toEqual(expected);
});

test('replaceThumbToVideo', () => {
const thumbPath = 'https://cdn/galleries/demo/media/thumbs/2021/2021-02-20-50.jpg';
const videoFilename = '2021-02-20-50.mp4';
const expected = 'https://cdn/galleries/demo/media/videos/2021/2021-02-20-50.mp4';
expect(replaceThumbToVideo(thumbPath, videoFilename)).toEqual(expected);
});
});

describe('determineAdjacentInCarousel', () => {
describe('Single use input', () => {
const testState = {
Expand Down

0 comments on commit 92a11d1

Please sign in to comment.