2023-11-19 15:52:48 +01:00
|
|
|
import os
|
2024-01-16 18:50:19 +01:00
|
|
|
import shutil
|
2023-11-19 18:45:25 +01:00
|
|
|
import sqlite3
|
2023-11-19 15:52:48 +01:00
|
|
|
from hooks import utils
|
2023-11-19 18:45:25 +01:00
|
|
|
from colorama import Fore, Style
|
2023-11-19 15:52:48 +01:00
|
|
|
|
2023-11-19 18:45:25 +01:00
|
|
|
"""
|
|
|
|
v1.3.*
|
|
|
|
"""
|
2023-12-15 13:38:32 +01:00
|
|
|
|
|
|
|
|
2023-11-19 15:52:48 +01:00
|
|
|
def add_source():
|
2023-12-15 13:38:32 +01:00
|
|
|
utils.run_sqlite_command("ALTER TABLE partition ADD source TEXT DEFAULT 'unknown'")
|
|
|
|
|
2023-11-19 15:52:48 +01:00
|
|
|
|
|
|
|
def add_groupes():
|
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""CREATE TABLE groupe (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
uuid TEXT(36) NOT NULL
|
2023-11-19 16:05:23 +01:00
|
|
|
);"""
|
|
|
|
)
|
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""CREATE TABLE groupe_contient_user (
|
2023-11-19 15:52:48 +01:00
|
|
|
groupe_id INTEGER NOT NULL,
|
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
is_admin INTEGER NOT NULL DEFAULT 0,
|
|
|
|
PRIMARY KEY (groupe_id, user_id)
|
2023-11-19 16:05:23 +01:00
|
|
|
);"""
|
|
|
|
)
|
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""CREATE TABLE groupe_contient_album (
|
2023-11-19 15:52:48 +01:00
|
|
|
groupe_id INTEGER NOT NULL,
|
|
|
|
album_id INTEGER NOT NULL,
|
|
|
|
PRIMARY KEY (groupe_id, album_id)
|
|
|
|
);"""
|
|
|
|
)
|
|
|
|
|
2023-12-15 13:38:32 +01:00
|
|
|
|
2023-11-19 15:52:48 +01:00
|
|
|
def add_attachments():
|
|
|
|
os.makedirs("partitioncloud/attachments", exist_ok=True)
|
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""CREATE TABLE attachments (
|
|
|
|
uuid TEXT(36) PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
filetype TEXT NOT NULL DEFAULT 'mp3',
|
|
|
|
partition_uuid INTEGER NOT NULL,
|
|
|
|
user_id INTEGER NOT NULL
|
|
|
|
);"""
|
|
|
|
)
|
|
|
|
|
2023-12-15 13:38:32 +01:00
|
|
|
|
2023-11-19 15:52:48 +01:00
|
|
|
def install_colorama():
|
2023-11-19 18:45:25 +01:00
|
|
|
os.system("pip install colorama -qq")
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
v1.4.*
|
|
|
|
"""
|
2023-12-15 13:38:32 +01:00
|
|
|
|
|
|
|
|
2023-11-19 18:45:25 +01:00
|
|
|
def mass_rename():
|
|
|
|
"""Rename all albums & groupes to use a shorter uuid"""
|
|
|
|
albums = utils.get_sqlite_data("SELECT * FROM album")
|
|
|
|
groupes = utils.get_sqlite_data("SELECT * FROM groupe")
|
|
|
|
|
2023-12-15 13:38:32 +01:00
|
|
|
utils.run_sqlite_command("ALTER TABLE groupe RENAME TO _groupe_old")
|
|
|
|
utils.run_sqlite_command("ALTER TABLE album RENAME TO _album_old")
|
2023-11-19 18:45:25 +01:00
|
|
|
|
2023-12-15 13:38:32 +01:00
|
|
|
utils.run_sqlite_command( # Add UNIQUE constraint & change uuid length
|
2023-11-19 18:45:25 +01:00
|
|
|
"""CREATE TABLE groupe (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
uuid TEXT(6) UNIQUE NOT NULL
|
|
|
|
);"""
|
|
|
|
)
|
|
|
|
|
2023-12-15 13:38:32 +01:00
|
|
|
utils.run_sqlite_command( # Change uuid length
|
2023-11-19 18:45:25 +01:00
|
|
|
"""CREATE TABLE album (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
uuid TEXT(6) UNIQUE NOT NULL
|
|
|
|
);"""
|
|
|
|
)
|
|
|
|
|
|
|
|
for album in albums:
|
|
|
|
try:
|
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""
|
|
|
|
INSERT INTO album (id, name, uuid)
|
|
|
|
VALUES (?, ?, ?)
|
|
|
|
""",
|
2023-12-15 13:38:32 +01:00
|
|
|
(album[0], album[1], utils.format_uuid(album[2])),
|
2023-11-19 18:45:25 +01:00
|
|
|
)
|
|
|
|
except sqlite3.IntegrityError:
|
2023-12-15 11:36:34 +01:00
|
|
|
uuid = utils.new_uuid()
|
2023-12-15 13:38:32 +01:00
|
|
|
print(
|
|
|
|
f"{Fore.RED}Collision on {album[1]}{Style.RESET_ALL} \
|
|
|
|
({album[2][:10]} renaming to {uuid})"
|
|
|
|
)
|
2023-11-19 18:45:25 +01:00
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""
|
|
|
|
INSERT INTO album (id, name, uuid)
|
|
|
|
VALUES (?, ?, ?)
|
|
|
|
""",
|
2023-12-15 13:38:32 +01:00
|
|
|
(album[0], album[1], uuid),
|
2023-11-19 18:45:25 +01:00
|
|
|
)
|
2023-12-15 11:36:34 +01:00
|
|
|
|
2023-11-19 18:45:25 +01:00
|
|
|
for groupe in groupes:
|
|
|
|
try:
|
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""
|
|
|
|
INSERT INTO groupe (id, name, uuid)
|
|
|
|
VALUES (?, ?, ?)
|
|
|
|
""",
|
2023-12-15 13:38:32 +01:00
|
|
|
(groupe[0], groupe[1], utils.format_uuid(groupe[2])),
|
2023-11-19 18:45:25 +01:00
|
|
|
)
|
|
|
|
except sqlite3.IntegrityError:
|
2023-12-15 11:36:34 +01:00
|
|
|
uuid = utils.new_uuid()
|
2023-12-15 13:38:32 +01:00
|
|
|
print(
|
|
|
|
f"{Fore.RED}Collision on {groupe[1]}{Style.RESET_ALL} \
|
|
|
|
({groupe[2][:10]} renaming to {uuid})"
|
|
|
|
)
|
2023-11-19 18:45:25 +01:00
|
|
|
utils.run_sqlite_command(
|
|
|
|
"""
|
|
|
|
INSERT INTO groupe (id, name, uuid)
|
|
|
|
VALUES (?, ?, ?)
|
|
|
|
""",
|
2023-12-15 13:38:32 +01:00
|
|
|
(groupe[0], groupe[1], uuid),
|
2023-11-19 18:45:25 +01:00
|
|
|
)
|
|
|
|
|
2023-12-15 13:38:32 +01:00
|
|
|
utils.run_sqlite_command("DROP TABLE _groupe_old")
|
|
|
|
utils.run_sqlite_command("DROP TABLE _album_old")
|
|
|
|
|
2023-11-19 18:45:25 +01:00
|
|
|
|
|
|
|
def base_url_parameter_added():
|
2023-12-15 13:38:32 +01:00
|
|
|
print(
|
|
|
|
f"{Style.BRIGHT}{Fore.YELLOW}The parameter BASE_URL has been added, \
|
|
|
|
reference your front url in it{Style.RESET_ALL}"
|
|
|
|
)
|
|
|
|
|
2023-11-19 19:03:56 +01:00
|
|
|
|
|
|
|
def install_qrcode():
|
2023-12-15 13:38:32 +01:00
|
|
|
os.system("pip install qrcode -qq")
|
2024-01-16 18:50:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
v1.5.*
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def move_instance():
|
|
|
|
paths = [
|
|
|
|
"attachments",
|
|
|
|
"partitions",
|
|
|
|
"search-partitions"
|
|
|
|
]
|
|
|
|
for path in paths:
|
|
|
|
shutil.move(
|
|
|
|
os.path.join("partitioncloud", path),
|
|
|
|
os.path.join("instance", path)
|
|
|
|
)
|