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 Jun 19, 2024
2 parents c8030c6 + 868c7da commit 2066143
Show file tree
Hide file tree
Showing 28 changed files with 195 additions and 51 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ jobs:
with:
path: |
_build
.cargo
deps
key: ${{ runner.os }}-build-deps-${{ hashFiles('mix.lock') }}
key: ${{ runner.os }}-deps-2-${{ hashFiles('mix.lock') }}

- name: Enable caching
run: |
# Disable volumes so caching can take effect
sed -i -Ee 's/- app_[a-z]+_data:.*$//g' docker-compose.yml
# Make ourselves the owner
echo "RUN addgroup -g $(id -g) -S appgroup && adduser -u $(id -u) -S appuser -G appgroup" >> docker/app/Dockerfile
echo "USER appuser" >> docker/app/Dockerfile
echo "RUN mix local.hex --force && mix local.rebar --force" >> docker/app/Dockerfile
- run: docker compose pull
- run: docker compose build
Expand All @@ -27,6 +38,18 @@ jobs:
run: |
docker compose run app mix sobelow --config
docker compose run app mix deps.audit
- name: Dialyzer
run: |
docker compose run app mix dialyzer
typos:
name: 'Check for spelling errors'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@master

lint-and-test:
name: 'JavaScript Linting and Unit Tests'
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[default]
extend-ignore-re = [
# Ignore development secret key. Production secret key should
# be in environment files and not checked into source control.
".*secret_key_base.*",

# Key constraints with encoded names
"fk_rails_[a-f0-9]+"
]

12 changes: 7 additions & 5 deletions assets/js/utils/__tests__/local-autocompleter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ describe('Local Autocompleter', () => {
});

describe('instantiation', () => {
it('should be constructable with compatible data', () => {
it('should be constructible with compatible data', () => {
const result = new LocalAutocompleter(mockData);
expect(result).toBeInstanceOf(LocalAutocompleter);
});

it('should NOT be constructable with incompatible data', () => {
it('should NOT be constructible with incompatible data', () => {
const versionDataOffset = 12;
const mockIncompatibleDataArray = new Array(versionDataOffset).fill(0);
// Set data version to 1
Expand All @@ -45,6 +45,8 @@ describe('Local Autocompleter', () => {
});

describe('topK', () => {
const termStem = ['f', 'o'].join('');

let localAc: LocalAutocompleter;

beforeAll(() => {
Expand All @@ -66,7 +68,7 @@ describe('Local Autocompleter', () => {
});

it('should return suggestions sorted by image count', () => {
const result = localAc.topK('fo', defaultK);
const result = localAc.topK(termStem, defaultK);
expect(result).toEqual([
expect.objectContaining({ name: 'forest', imageCount: 3 }),
expect.objectContaining({ name: 'fog', imageCount: 1 }),
Expand All @@ -82,13 +84,13 @@ describe('Local Autocompleter', () => {
});

it('should return only the required number of suggestions', () => {
const result = localAc.topK('fo', 1);
const result = localAc.topK(termStem, 1);
expect(result).toEqual([expect.objectContaining({ name: 'forest', imageCount: 3 })]);
});

it('should NOT return suggestions associated with hidden tags', () => {
window.booru.hiddenTagList = [1];
const result = localAc.topK('fo', defaultK);
const result = localAc.topK(termStem, defaultK);
expect(result).toEqual([]);
});

Expand Down
6 changes: 3 additions & 3 deletions assets/package-lock.json

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

2 changes: 1 addition & 1 deletion lib/philomena/comments/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule Philomena.Comments.Query do

defp parse(fields, context, query_string) do
fields
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string, context)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/filters/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Philomena.Filters.Query do

defp parse(fields, context, query_string) do
fields
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string, context)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/galleries/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Philomena.Galleries.Query do
query_string = query_string || ""

fields()
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string)
end
end
2 changes: 1 addition & 1 deletion lib/philomena/images/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule Philomena.Images.Query do

defp parse(fields, context, query_string) do
fields
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string, context)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/posts/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ defmodule Philomena.Posts.Query do

defp parse(fields, context, query_string) do
fields
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string, context)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/reports/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Philomena.Reports.Query do

def compile(query_string) do
fields()
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string || "", %{})
end
end
2 changes: 1 addition & 1 deletion lib/philomena/tags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ defmodule Philomena.Tags do
|> where(tag_id: ^tag.id)
|> Repo.delete_all()

# Update other assocations
# Update other associations
ArtistLink
|> where(tag_id: ^tag.id)
|> Repo.update_all(set: [tag_id: target_tag.id])
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/tags/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Philomena.Tags.Query do

def compile(query_string) do
fields()
|> Parser.parser()
|> Parser.new()
|> Parser.parse(query_string || "")
end
end
2 changes: 1 addition & 1 deletion lib/philomena/users/user_notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule Philomena.Users.UserNotifier do
Your account has been automatically locked due to too many attempts to sign in.
You can unlock your account by visting the URL below:
You can unlock your account by visiting the URL below:
#{url}
Expand Down
3 changes: 3 additions & 0 deletions lib/philomena_media/analyzers/analyzer.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
defmodule PhilomenaMedia.Analyzers.Analyzer do
@moduledoc false

@doc """
Generate a `m:PhilomenaMedia.Analyzers.Result` for file at the given path.
"""
@callback analyze(Path.t()) :: PhilomenaMedia.Analyzers.Result.t()
end
2 changes: 1 addition & 1 deletion lib/philomena_media/intensities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule PhilomenaMedia.Intensities do
> #### Info {: .info}
>
> Clients should prefer to use `m:PhilomenaMedia.Processors.intensities/2`, as it handles
> Clients should prefer to use `PhilomenaMedia.Processors.intensities/2`, as it handles
> media files of any type supported by this library, not just PNG or JPEG.
## Examples
Expand Down
18 changes: 10 additions & 8 deletions lib/philomena_media/processors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,31 @@ defmodule PhilomenaMedia.Processors do
alias PhilomenaMedia.Processors.{Gif, Jpeg, Png, Svg, Webm}
alias PhilomenaMedia.Mime

# The name of a version, like :large
@typedoc "The name of a version, like `:large`."
@type version_name :: atom()

@type dimensions :: {integer(), integer()}
@type version_list :: [{version_name(), dimensions()}]

# The file name of a processed version, like "large.png"
@typedoc "The file name of a processed version, like `large.png`."
@type version_filename :: String.t()

# A single file to be copied to satisfy a request for a version name
@typedoc "A single file to be copied to satisfy a request for a version name."
@type copy_request :: {:copy, Path.t(), version_filename()}

# A list of thumbnail versions to copy into place
@typedoc "A list of thumbnail versions to copy into place."
@type thumbnails :: {:thumbnails, [copy_request()]}

# Replace the original file to strip metadata or losslessly optimize
@typedoc "Replace the original file to strip metadata or losslessly optimize."
@type replace_original :: {:replace_original, Path.t()}

# Apply the computed corner intensities
@typedoc "Apply the computed corner intensities."
@type intensities :: {:intensities, Intensities.t()}

# An edit script, representing the changes to apply to the storage backend
# after successful processing
@typedoc """
An edit script, representing the changes to apply to the storage backend
after successful processing.
"""
@type edit_script :: [thumbnails() | replace_original() | intensities()]

@doc """
Expand Down
20 changes: 14 additions & 6 deletions lib/philomena_media/processors/processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ defmodule PhilomenaMedia.Processors.Processor do
alias PhilomenaMedia.Processors
alias PhilomenaMedia.Intensities

# Generate a list of version filenames for the given version list.
@doc """
Generate a list of version filenames for the given version list.
"""
@callback versions(Processors.version_list()) :: [Processors.version_filename()]

# Process the media at the given path against the given version list, and return an
# edit script with the resulting files
@doc """
Process the media at the given path against the given version list, and return an
edit script with the resulting files.
"""
@callback process(Result.t(), Path.t(), Processors.version_list()) :: Processors.edit_script()

# Perform post-processing optimization tasks on the file, to reduce its size
# and strip non-essential metadata
@doc """
Perform post-processing optimization tasks on the file, to reduce its size
and strip non-essential metadata.
"""
@callback post_process(Result.t(), Path.t()) :: Processors.edit_script()

# Generate corner intensities for the given path
@doc """
Generate corner intensities for the given path.
"""
@callback intensities(Result.t(), Path.t()) :: Intensities.t()
end
6 changes: 3 additions & 3 deletions lib/philomena_proxy/scrapers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ defmodule PhilomenaProxy.Scrapers do
Scrape utilities to facilitate uploading media from other websites.
"""

# The URL to fetch, as a string.
@typedoc "The URL to fetch, as a string."
@type url :: String.t()

# An individual image in a list associated with a scrape result.
@typedoc "An individual image in a list associated with a scrape result."
@type image_result :: %{
url: url(),
camo_url: url()
}

# Result of a successful scrape.
@typedoc "Result of a successful scrape."
@type scrape_result :: %{
source_url: url(),
description: String.t() | nil,
Expand Down
18 changes: 18 additions & 0 deletions lib/philomena_query/batch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,31 @@ defmodule PhilomenaQuery.Batch do
alias Philomena.Repo
import Ecto.Query

@typedoc """
Represents an object which may be operated on via `m:Ecto.Query`.
This could be a schema object (e.g. `m:Philomena.Images.Image`) or a fully formed query
`from i in Image, where: i.hidden_from_users == false`.
"""
@type queryable :: any()

@type batch_size :: {:batch_size, integer()}
@type id_field :: {:id_field, atom()}
@type batch_options :: [batch_size() | id_field()]

@typedoc """
The callback for `record_batches/3`.
Takes a list of schema structs which were returned in the batch. Return value is ignored.
"""
@type record_batch_callback :: ([struct()] -> any())

@typedoc """
The callback for `query_batches/3`.
Takes an `m:Ecto.Query` that can be processed with `m:Philomena.Repo` query commands, such
as `Philomena.Repo.update_all/3` or `Philomena.Repo.delete_all/2`. Return value is ignored.
"""
@type query_batch_callback :: ([Ecto.Query.t()] -> any())

@doc """
Expand Down
28 changes: 25 additions & 3 deletions lib/philomena_query/parse/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,34 @@ defmodule PhilomenaQuery.Parse.Parser do
TermRangeParser
}

@typedoc """
User-supplied context argument.
Provided to `parse/3` and passed to the transform callback.
"""
@type context :: any()

@typedoc "Query in the search engine JSON query language."
@type query :: map()

@typedoc "Whether the default field is `:term` (not analyzed) or `:ngram` (analyzed)."
@type default_field_type :: :term | :ngram

@typedoc """
Return value of the transform callback.
On `{:ok, query}`, the query is incorporated into the parse tree at the current location.
On `{:error, error}`, parsing immediately stops and the error is returned from the parser.
"""
@type transform_result :: {:ok, query()} | {:error, String.t()}

@typedoc """
Type of the transform callback.
The transform callback receives the context argument passed to `parse/3` and the remainder of
the term. For instance `my:example` would match a transform rule with the key `"my"`, and
the remainder passed to the callback would be `"example"`.
"""
@type transform :: (context, String.t() -> transform_result())

@type t :: %__MODULE__{
Expand Down Expand Up @@ -112,11 +134,11 @@ defmodule PhilomenaQuery.Parse.Parser do
aliases: %{"hidden" => "hidden_from_users"}
]
Parser.parser(options)
Parser.new(options)
"""
@spec parser(keyword()) :: t()
def parser(options) do
@spec new(keyword()) :: t()
def new(options) do
parser = struct(Parser, options)

fields =
Expand Down
Loading

0 comments on commit 2066143

Please sign in to comment.