feat: move storage path setting to configuration file
- change default storage path to /srv/libretime - remove music dirs table - use /tmp for testing storage - storage dir should always have a trailing slash
This commit is contained in:
parent
b3ff2defc4
commit
f7bb6e7592
48 changed files with 464 additions and 4701 deletions
41
api/libretime_api/legacy/migrations/0029_3_0_0_alpha_13_3.py
Normal file
41
api/libretime_api/legacy/migrations/0029_3_0_0_alpha_13_3.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from django.db import migrations
|
||||
|
||||
from ._migrations import legacy_migration_factory
|
||||
|
||||
UP = """
|
||||
ALTER TABLE "cc_files" DROP CONSTRAINT "cc_music_dirs_folder_fkey";
|
||||
ALTER TABLE "cc_files" DROP COLUMN "directory";
|
||||
DROP TABLE "cc_music_dirs";
|
||||
"""
|
||||
|
||||
DOWN = """
|
||||
CREATE TABLE "cc_music_dirs"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"directory" TEXT,
|
||||
"type" VARCHAR(255),
|
||||
"exists" BOOLEAN DEFAULT 't',
|
||||
"watched" BOOLEAN DEFAULT 't',
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "cc_music_dir_unique" UNIQUE ("directory")
|
||||
);
|
||||
|
||||
ALTER TABLE "cc_files" ADD COLUMN "directory" INTEGER;
|
||||
ALTER TABLE "cc_files" ADD CONSTRAINT "cc_music_dirs_folder_fkey"
|
||||
FOREIGN KEY ("directory")
|
||||
REFERENCES "cc_music_dirs" ("id");
|
||||
"""
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("legacy", "0028_3_0_0_alpha_13_2"),
|
||||
]
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
code=legacy_migration_factory(
|
||||
target="3.0.0-alpha.13.3",
|
||||
sql=UP,
|
||||
)
|
||||
)
|
||||
]
|
|
@ -1 +1 @@
|
|||
LEGACY_SCHEMA_VERSION = "3.0.0-alpha.13.2"
|
||||
LEGACY_SCHEMA_VERSION = "3.0.0-alpha.13.3"
|
||||
|
|
|
@ -1,21 +1,4 @@
|
|||
|
||||
-----------------------------------------------------------------------
|
||||
-- cc_music_dirs
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS "cc_music_dirs" CASCADE;
|
||||
|
||||
CREATE TABLE "cc_music_dirs"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"directory" TEXT,
|
||||
"type" VARCHAR(255),
|
||||
"exists" BOOLEAN DEFAULT 't',
|
||||
"watched" BOOLEAN DEFAULT 't',
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "cc_music_dir_unique" UNIQUE ("directory")
|
||||
);
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- cc_files
|
||||
-----------------------------------------------------------------------
|
||||
|
@ -28,7 +11,6 @@ CREATE TABLE "cc_files"
|
|||
"name" VARCHAR(255) DEFAULT '' NOT NULL,
|
||||
"mime" VARCHAR(255) DEFAULT '' NOT NULL,
|
||||
"ftype" VARCHAR(128) DEFAULT '' NOT NULL,
|
||||
"directory" INTEGER,
|
||||
"filepath" TEXT DEFAULT '',
|
||||
"import_status" INTEGER DEFAULT 1 NOT NULL,
|
||||
"currentlyaccessing" INTEGER DEFAULT 0 NOT NULL,
|
||||
|
@ -792,10 +774,6 @@ ALTER TABLE "cc_files" ADD CONSTRAINT "cc_files_editedby_fkey"
|
|||
FOREIGN KEY ("editedby")
|
||||
REFERENCES "cc_subjs" ("id");
|
||||
|
||||
ALTER TABLE "cc_files" ADD CONSTRAINT "cc_music_dirs_folder_fkey"
|
||||
FOREIGN KEY ("directory")
|
||||
REFERENCES "cc_music_dirs" ("id");
|
||||
|
||||
ALTER TABLE "cloud_file" ADD CONSTRAINT "cloud_file_FK_1"
|
||||
FOREIGN KEY ("cc_file_id")
|
||||
REFERENCES "cc_files" ("id")
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.utils import dateparse
|
|||
from model_bakery import baker
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from ...._fixtures import AUDIO_FILENAME, fixture_path
|
||||
from ...._fixtures import AUDIO_FILENAME
|
||||
|
||||
|
||||
class TestScheduleViewSet(APITestCase):
|
||||
|
@ -15,13 +15,8 @@ class TestScheduleViewSet(APITestCase):
|
|||
cls.token = settings.CONFIG.general.api_key
|
||||
|
||||
def test_schedule_item_full_length(self):
|
||||
music_dir = baker.make(
|
||||
"storage.MusicDir",
|
||||
directory=str(fixture_path),
|
||||
)
|
||||
file = baker.make(
|
||||
"storage.File",
|
||||
directory=music_dir,
|
||||
mime="audio/mp3",
|
||||
filepath=AUDIO_FILENAME,
|
||||
length=timedelta(seconds=40.86),
|
||||
|
@ -51,13 +46,8 @@ class TestScheduleViewSet(APITestCase):
|
|||
self.assertEqual(dateparse.parse_duration(result[0]["cue_out"]), file.cueout)
|
||||
|
||||
def test_schedule_item_trunc(self):
|
||||
music_dir = baker.make(
|
||||
"storage.MusicDir",
|
||||
directory=str(fixture_path),
|
||||
)
|
||||
file = baker.make(
|
||||
"storage.File",
|
||||
directory=music_dir,
|
||||
mime="audio/mp3",
|
||||
filepath=AUDIO_FILENAME,
|
||||
length=timedelta(seconds=40.86),
|
||||
|
@ -88,13 +78,8 @@ class TestScheduleViewSet(APITestCase):
|
|||
)
|
||||
|
||||
def test_schedule_item_invalid(self):
|
||||
music_dir = baker.make(
|
||||
"storage.MusicDir",
|
||||
directory=str(fixture_path),
|
||||
)
|
||||
file = baker.make(
|
||||
"storage.File",
|
||||
directory=music_dir,
|
||||
mime="audio/mp3",
|
||||
filepath=AUDIO_FILENAME,
|
||||
length=timedelta(seconds=40.86),
|
||||
|
@ -134,13 +119,8 @@ class TestScheduleViewSet(APITestCase):
|
|||
self.assertEqual(dateparse.parse_duration(result[0]["cue_out"]), file.cueout)
|
||||
|
||||
def test_schedule_item_range(self):
|
||||
music_dir = baker.make(
|
||||
"storage.MusicDir",
|
||||
directory=str(fixture_path),
|
||||
)
|
||||
file = baker.make(
|
||||
"storage.File",
|
||||
directory=music_dir,
|
||||
mime="audio/mp3",
|
||||
filepath=AUDIO_FILENAME,
|
||||
length=timedelta(seconds=40.86),
|
||||
|
|
|
@ -3,6 +3,7 @@ from libretime_shared.config import (
|
|||
DatabaseConfig,
|
||||
GeneralConfig,
|
||||
RabbitMQConfig,
|
||||
StorageConfig,
|
||||
)
|
||||
|
||||
|
||||
|
@ -10,3 +11,4 @@ class Config(BaseConfig):
|
|||
general: GeneralConfig
|
||||
database: DatabaseConfig = DatabaseConfig()
|
||||
rabbitmq: RabbitMQConfig = RabbitMQConfig()
|
||||
storage: StorageConfig = StorageConfig()
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import os
|
||||
|
||||
from .._fixtures import fixture_path
|
||||
|
||||
os.environ.setdefault("LIBRETIME_DEBUG", "true")
|
||||
os.environ.setdefault("LIBRETIME_GENERAL_PUBLIC_URL", "http://localhost")
|
||||
os.environ.setdefault("LIBRETIME_GENERAL_API_KEY", "testing")
|
||||
os.environ.setdefault("LIBRETIME_STORAGE_PATH", str(fixture_path))
|
||||
|
||||
# pylint: disable=wrong-import-position,unused-import
|
||||
from .prod import (
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from .cloud_file import CloudFile
|
||||
from .file import File
|
||||
from .storage import MusicDir
|
||||
from .track_type import TrackType
|
||||
|
|
|
@ -5,9 +5,6 @@ class File(models.Model):
|
|||
name = models.CharField(max_length=255)
|
||||
mime = models.CharField(max_length=255)
|
||||
ftype = models.CharField(max_length=128)
|
||||
directory = models.ForeignKey(
|
||||
"MusicDir", models.DO_NOTHING, db_column="directory", blank=True, null=True
|
||||
)
|
||||
filepath = models.TextField(blank=True, null=True)
|
||||
import_status = models.IntegerField()
|
||||
currently_accessing = models.IntegerField(db_column="currentlyaccessing")
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class MusicDir(models.Model):
|
||||
directory = models.TextField(unique=True, blank=True, null=True)
|
||||
type = models.CharField(max_length=255, blank=True, null=True)
|
||||
exists = models.BooleanField(blank=True, null=True)
|
||||
watched = models.BooleanField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_music_dirs"
|
|
@ -1,9 +1,8 @@
|
|||
from rest_framework import routers
|
||||
|
||||
from .views import CloudFileViewSet, FileViewSet, MusicDirViewSet, TrackTypeViewSet
|
||||
from .views import CloudFileViewSet, FileViewSet, TrackTypeViewSet
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register("files", FileViewSet)
|
||||
router.register("music-dirs", MusicDirViewSet)
|
||||
router.register("cloud-files", CloudFileViewSet)
|
||||
router.register("track-types", TrackTypeViewSet)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from .cloud_file import CloudFileSerializer
|
||||
from .file import FileSerializer
|
||||
from .storage import MusicDirSerializer
|
||||
from .track_type import TrackTypeSerializer
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from ..models import MusicDir
|
||||
|
||||
|
||||
class MusicDirSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = MusicDir
|
||||
fields = "__all__"
|
|
@ -24,13 +24,8 @@ class TestFileViewSet(APITestCase):
|
|||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_exists(self):
|
||||
music_dir = baker.make(
|
||||
"storage.MusicDir",
|
||||
directory=str(fixture_path),
|
||||
)
|
||||
file = baker.make(
|
||||
"storage.File",
|
||||
directory=music_dir,
|
||||
mime="audio/mp3",
|
||||
filepath=AUDIO_FILENAME,
|
||||
)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from .cloud_file import CloudFileViewSet
|
||||
from .file import FileViewSet
|
||||
from .storage import MusicDirViewSet
|
||||
from .track_type import TrackTypeViewSet
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import FileResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import viewsets
|
||||
|
@ -20,7 +21,5 @@ class FileViewSet(viewsets.ModelViewSet):
|
|||
pk = IntegerField().to_internal_value(data=pk)
|
||||
|
||||
file = get_object_or_404(File, pk=pk)
|
||||
storage = file.directory
|
||||
path = os.path.join(storage.directory, file.filepath)
|
||||
|
||||
path = os.path.join(settings.CONFIG.storage.path, file.filepath)
|
||||
return FileResponse(open(path, "rb"), content_type=file.mime)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
from rest_framework import viewsets
|
||||
|
||||
from ..models import MusicDir
|
||||
from ..serializers import MusicDirSerializer
|
||||
|
||||
|
||||
class MusicDirViewSet(viewsets.ModelViewSet):
|
||||
queryset = MusicDir.objects.all()
|
||||
serializer_class = MusicDirSerializer
|
||||
model_permission_name = "musicdir"
|
Loading…
Add table
Add a link
Reference in a new issue