Use Upload Media logic from Pleroma Backend changes for picture upload Move AS <-> Model conversion to separate module Front changes Downgrade apollo-client: https://github.com/Akryum/vue-apollo/issues/577 Signed-off-by: Thomas Citharel <tcit@tcit.fr>master
parent
9724bc8e9f
commit
f90089e1bf
@ -0,0 +1,29 @@
|
||||
<template>
|
||||
<b-field class="file">
|
||||
<b-upload v-model="pictureFile" @input="onFileChanged">
|
||||
<a class="button is-primary">
|
||||
<b-icon icon="upload"></b-icon>
|
||||
<span>Click to upload</span>
|
||||
</a>
|
||||
</b-upload>
|
||||
<span class="file-name" v-if="pictureFile">
|
||||
{{ pictureFile.name }}
|
||||
</span>
|
||||
</b-field>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import { IPictureUpload } from '@/types/picture.model';
|
||||
|
||||
@Component
|
||||
export default class PictureUpload extends Vue {
|
||||
picture!: IPictureUpload;
|
||||
pictureFile: File|null = null;
|
||||
|
||||
onFileChanged(file: File) {
|
||||
this.picture = { file, name: file.name, alt: '' };
|
||||
this.$emit('change', this.picture);
|
||||
}
|
||||
}
|
||||
</script>
|
@ -0,0 +1,16 @@
|
||||
export interface IAbstractPicture {
|
||||
name;
|
||||
alt;
|
||||
}
|
||||
|
||||
export interface IPicture {
|
||||
url;
|
||||
name;
|
||||
alt;
|
||||
}
|
||||
|
||||
export interface IPictureUpload {
|
||||
file: File;
|
||||
name: String;
|
||||
alt: String|null;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,115 @@
|
||||
defmodule Mobilizon.Media do
|
||||
@moduledoc """
|
||||
The Media context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Mobilizon.Repo
|
||||
|
||||
alias Mobilizon.Media.Picture
|
||||
|
||||
@doc false
|
||||
def data() do
|
||||
Dataloader.Ecto.new(Mobilizon.Repo, query: &query/2)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def query(queryable, _params) do
|
||||
queryable
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single picture.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Picture does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_picture!(123)
|
||||
%Picture{}
|
||||
|
||||
iex> get_picture!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_picture!(id), do: Repo.get!(Picture, id)
|
||||
|
||||
def get_picture(id), do: Repo.get(Picture, id)
|
||||
|
||||
@doc """
|
||||
Get a picture by it's URL
|
||||
"""
|
||||
@spec get_picture_by_url(String.t()) :: Picture.t() | nil
|
||||
def get_picture_by_url(url) do
|
||||
from(
|
||||
p in Picture,
|
||||
where: fragment("? @> ?", p.file, ~s|{"url": "#{url}"}|)
|
||||
)
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a picture.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_picture(%{field: value})
|
||||
{:ok, %Picture{}}
|
||||
|
||||
iex> create_picture(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_picture(attrs \\ %{}) do
|
||||
%Picture{}
|
||||
|> Picture.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a picture.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_picture(picture, %{field: new_value})
|
||||
{:ok, %Picture{}}
|
||||
|
||||
iex> update_picture(picture, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_picture(%Picture{} = picture, attrs) do
|
||||
picture
|
||||
|> Picture.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a Picture.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_picture(picture)
|
||||
{:ok, %Picture{}}
|
||||
|
||||
iex> delete_picture(picture)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_picture(%Picture{} = picture) do
|
||||
Repo.delete(picture)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking picture changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_picture(picture)
|
||||
%Ecto.Changeset{source: %Picture{}}
|
||||
|
||||
"""
|
||||
def change_picture(%Picture{} = picture) do
|
||||
Picture.changeset(picture, %{})
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
defmodule Mobilizon.Media.File do
|
||||
@moduledoc """
|
||||
Represents a file entity
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
embedded_schema do
|
||||
field(:name, :string)
|
||||
field |