• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / a2bc0383-1205-4ebd-979f-e7ee6dba9a0d

18 Dec 2023 05:15PM UTC coverage: 73.514% (-0.7%) from 74.258%
a2bc0383-1205-4ebd-979f-e7ee6dba9a0d

push

circleci

jwhitlock
Add provider_id="" to SocialApp init

1962 of 2913 branches covered (0.0%)

Branch coverage included in aggregate %.

6273 of 8289 relevant lines covered (75.68%)

19.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.78
/privaterelay/storage.py
1
"""
2
Staticfiles storage implementation for Relay.
3

4
This is used when running ./manage.py collectstatic, or rendering Django templates.
5
"""
6
from typing import Any
1✔
7

8
from whitenoise.storage import CompressedManifestStaticFilesStorage
1✔
9

10

11
class RelayStaticFilesStorage(CompressedManifestStaticFilesStorage):
1✔
12
    """
13
    Customize Whitenoise storage for Relay
14

15
    The Django ManifestStaticFilesStorage creates a copy of each file that
16
    includes a hash of its contents, and serves these with a long cache time.
17
    It also creates staticfiles/staticfiles.json that lists all the known static
18
    files, rather than scanning the folder for files at startup.
19

20
    The Whitenoise CompressedManifestStaticFilesStorage builds on this by
21
    pre-compressing files as well, so that the gzipped versions can be served.
22

23
    This class skips renaming files from Next.js, which already include hashes
24
    in the filenames.
25

26
    See:
27
    https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/#manifeststaticfilesstorage
28
    http://whitenoise.evans.io/en/stable/django.html#add-compression-and-caching-support
29
    """
30

31
    def hashed_name(
1✔
32
        self, name: str, content: str | None = None, filename: str | None = None
33
    ) -> str:
34
        """Skip hashing filenames output by Next.js"""
35
        if name.startswith("_next/static/"):
×
36
            return name
×
37
        else:
38
            new_name = super().hashed_name(name, content, filename)
×
39
            assert isinstance(new_name, str)
×
40
            return new_name
×
41

42
    def url_converter(
1✔
43
        self, name: str, hashed_files: dict[str, str], template: str | None = None
44
    ) -> Any:
45
        """
46
        Convert Next.js source map URL to absolute URL.
47

48
        If this changes, or other django.contrib.staticfiles changes adjust CSS output,
49
        then update the cache version in globals.scss and tokens.scss to bust the cache.
50
        """
51
        if (
×
52
            name.startswith("_next/static/css/")
53
            and name.endswith(".css")
54
            and template == "/*# sourceMappingURL=%(url)s */"
55
        ):
56
            path = name.rsplit("/", 1)[0]
×
57
            template = f"/*# sourceMappingURL={self.base_url}{path}/%(url)s */"
×
58
        return super().url_converter(name, hashed_files, template)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc