Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed May 21, 2024
2 parents 41e2599 + b9db906 commit 8b869b5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 37 deletions.
5 changes: 3 additions & 2 deletions assets/js/image_expansion.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ function pickAndResize(elem) {
}

const muted = store.get('unmute_videos') ? '' : 'muted';
const autoplay = elem.classList.contains('hidden') ? '' : 'autoplay'; // Fix for spoilered image pages

if (imageFormat === 'mp4') {
elem.classList.add('full-height');
elem.insertAdjacentHTML('afterbegin',
`<video controls autoplay loop ${muted} playsinline preload="auto" id="image-display"
`<video controls ${autoplay} loop ${muted} playsinline preload="auto" id="image-display"
width="${imageWidth}" height="${imageHeight}">
<source src="${uris.webm}" type="video/webm">
<source src="${uris.mp4}" type="video/mp4">
Expand All @@ -104,7 +105,7 @@ function pickAndResize(elem) {
}
else if (imageFormat === 'webm') {
elem.insertAdjacentHTML('afterbegin',
`<video controls autoplay loop ${muted} playsinline id="image-display">
`<video controls ${autoplay} loop ${muted} playsinline id="image-display">
<source src="${uri}" type="video/webm">
<source src="${uri.replace(/webm$/, 'mp4')}" type="video/mp4">
<p class="block block--fixed block--warning">
Expand Down
13 changes: 13 additions & 0 deletions assets/js/utils/__tests__/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ describe('Image utils', () => {
expect(mockShowElement).toHaveClass(spoilerPendingClass);
});

it('should play the video if it is present', () => {
const mockElement = document.createElement('div');
const { mockShowElement } = createImageShowElement(mockElement);
const mockVideo = document.createElement('video');
mockShowElement.appendChild(mockVideo);

const playSpy = vi.spyOn(mockVideo, 'play').mockReturnValue(Promise.resolve());

showBlock(mockElement);

expect(playSpy).toHaveBeenCalledTimes(1);
});

it('should not throw if image-filtered element is missing', () => {
const mockElement = document.createElement('div');
createImageShowElement(mockElement);
Expand Down
6 changes: 6 additions & 0 deletions assets/js/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ export function showThumb(img: HTMLDivElement) {
export function showBlock(img: HTMLDivElement) {
img.querySelector('.image-filtered')?.classList.add('hidden');
const imageShowClasses = img.querySelector('.image-show')?.classList;

if (imageShowClasses) {
imageShowClasses.remove('hidden');
imageShowClasses.add('spoiler-pending');

const vidEl = img.querySelector('video');
if (vidEl) {
vidEl.play();
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ version: '3'
volumes:
postgres_data: {}
elastic_data: {}
app_cargo_data: {}
app_build_data: {}
app_deps_data: {}
app_native_data: {}

services:
app:
Expand Down Expand Up @@ -44,6 +48,10 @@ services:
tty: true
volumes:
- .:/srv/philomena
- app_cargo_data:/srv/philomena/.cargo
- app_build_data:/srv/philomena/_build
- app_deps_data:/srv/philomena/deps
- app_native_data:/srv/philomena/priv/native
depends_on:
- postgres
- elasticsearch
Expand Down
5 changes: 4 additions & 1 deletion lib/philomena_web/plugs/user_attribution_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule PhilomenaWeb.UserAttributionPlug do
attributes = [
ip: remote_ip,
fingerprint: fingerprint(conn, conn.path_info),
referrer: conn.assigns.referrer,
referrer: referrer(conn.assigns.referrer),
user: user,
user_agent: user_agent(conn)
]
Expand All @@ -47,4 +47,7 @@ defmodule PhilomenaWeb.UserAttributionPlug do
defp fingerprint(conn, _) do
conn.cookies["_ses"]
end

defp referrer(nil), do: nil
defp referrer(r), do: String.slice(r, 0, 255)
end
57 changes: 23 additions & 34 deletions native/philomena/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b869b5

Please sign in to comment.