Compare commits
133 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 489d13227b | |||
| 0e6438cf0d | |||
| 00615532ce | |||
| abd16eeba2 | |||
| 5c9fcf2ec5 | |||
| 6bedab0d88 | |||
| 686e0d8f1f | |||
| 05a9134aaa | |||
| 3cadac4efd | |||
| 2188c2b746 | |||
| 9328f3d3da | |||
| ca13f101d7 | |||
| 1e4ffc798e | |||
| ecd025346c | |||
| 74184fa022 | |||
| c2a2ca049d | |||
| 157887bfac | |||
|
2b77bb978c
|
|||
| 206ebf03be | |||
| 0d7d57bf5f | |||
| 11b8cc21d3 | |||
| e109789b18 | |||
| ec0cbd7da0 | |||
| 809f27cf01 | |||
| 8a07718ce8 | |||
| 77cb5c8599 | |||
| dbcfcfa109 | |||
| 8b2b2f82e9 | |||
| 8e6ddbc9df | |||
| c8ba6606be | |||
| b7d55ebcf4 | |||
| d5f95ddf9b | |||
| 885f1db3af | |||
| d6f45c8279 | |||
| 58a88b1abd | |||
| 9b181733a6 | |||
| 219b95bb2f | |||
| 24e066d8d9 | |||
| ab08792ff4 | |||
| 9799edef33 | |||
| 92eb31a687 | |||
| aa946a0a05 | |||
| 19d6f2dc33 | |||
| 4824e6f33a | |||
| 64935ea772 | |||
| de90b0d0a1 | |||
| 19b943eed8 | |||
| 8c781398b4 | |||
| c575d2e523 | |||
| 03ed3deae6 | |||
| b69c111b66 | |||
| 8d97d4eb70 | |||
| 2f00ce6abf | |||
| e3cd1f4018 | |||
| a9f9ba8350 | |||
| df60bef381 | |||
| 038142eb8a | |||
| 69b81bc15c | |||
| b2e246d175 | |||
| c76e7b71b5 | |||
| b8dccca158 | |||
| b52607b4e3 | |||
| ac970a4302 | |||
| a372bfcc05 | |||
| d22850b280 | |||
| 4d170f6a85 | |||
| 7391b1db68 | |||
| 772641a8c4 | |||
| 4c99f88baf | |||
| c3718c5add | |||
| a4d026e41f | |||
| 6aa6f548a9 | |||
| 53b83a809c | |||
| ee4469b385 | |||
| 5e9e7bc46a | |||
| 5d02c47b86 | |||
| 7abf5d5db2 | |||
| 42dcbb87ed | |||
| 31b633e5f8 | |||
| 8788106352 | |||
| 9957a7c6eb | |||
| ae3b18c21f | |||
| 60b1d49ae6 | |||
| 1df7258993 | |||
| 68aa9f2245 | |||
| 8df10ed210 | |||
| e70a38d24b | |||
| a593c5099d | |||
| 639bf24c97 | |||
| a3a8084e69 | |||
| bb1e8a42ef | |||
| bc5112df38 | |||
| c96ee39c6a | |||
| 389f41ecea | |||
| 10bf0fb0e1 | |||
| 4429f7e766 | |||
| e5d119d343 | |||
| 1d88a3ccf6 | |||
| 2768c1e351 | |||
| 3955942988 | |||
| bfd7a02970 | |||
| 77acd15105 | |||
| 435a0df941 | |||
| c624c4de51 | |||
| 1d6cd804be | |||
| 2743543102 | |||
| 3195011f99 | |||
| ed5ceedb44 | |||
| f70acba704 | |||
| f224b5738b | |||
| c41cd9dbb7 | |||
| 9420ee97b4 | |||
| c46f386d70 | |||
| d9962749c8 | |||
| c8e8c1a460 | |||
| dcfa9951d9 | |||
| e90278995a | |||
| 7c8e77f233 | |||
| a1b2e5f64a | |||
| 25e8774968 | |||
| 10ed33d412 | |||
| 1ef40bcbfb | |||
| 3e25dd77b5 | |||
| 14d3c9acc6 | |||
| 9930aab985 | |||
| 0839731ee8 | |||
| 7a04b802f0 | |||
| 63d6022d16 | |||
| db1a6302ad | |||
| bd819f0332 | |||
| 7177b01a98 | |||
| 996b84c25c | |||
| 9d8122df5c |
@@ -0,0 +1,39 @@
|
|||||||
|
name: Rust
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Rust version
|
||||||
|
run: rustup install 1.95 && rustup default 1.95
|
||||||
|
|
||||||
|
- name: Debug secret
|
||||||
|
run: echo "${{ secrets.MYREPO_TOKEN }}" | head -c 10 ; echo "..."
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$EXTREPO_KEY" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan ${{ vars.MYHOST }}= >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo build --release
|
||||||
|
env:
|
||||||
|
EXTREPO_KEY: ${{ secrets.MYREPO_TOKEN }}
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --verbose
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/.vs/*
|
||||||
|
/build
|
||||||
|
/x64
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
.vscode/
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
|
||||||
|
|
||||||
|
|
||||||
include("cmake/HunterGate.cmake")
|
|
||||||
HunterGate(
|
|
||||||
URL "https://github.com/ruslo/hunter/archive/v0.23.184.tar.gz"
|
|
||||||
SHA1 "fe3fb05d51c21499c7eebbe7d0e102742a54a9cd"
|
|
||||||
)
|
|
||||||
|
|
||||||
project(IcarusDownloadManager)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(NOT ${CMAKE_VERSION} LESS 3.2)
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
else()
|
|
||||||
message(STATUS "Checking compiler flags for C++17 support.")
|
|
||||||
# Set C++17 support flags for various compilers
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
|
|
||||||
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
|
||||||
if(COMPILER_SUPPORTS_CXX17)
|
|
||||||
message(STATUS "C++17 is supported.")
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++")
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
|
||||||
endif()
|
|
||||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
|
||||||
message(STATUS "C++0x is supported.")
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
set(SOURCES
|
|
||||||
src/Main.cpp
|
|
||||||
src/Managers/ActionManager.cpp
|
|
||||||
src/Managers/CommitManager.cpp
|
|
||||||
src/Managers/FileManager.cpp
|
|
||||||
src/Managers/TokenManager.cpp
|
|
||||||
src/Managers/UserManager.cpp
|
|
||||||
src/Parsers/APIParser.cpp
|
|
||||||
src/Syncers/Delete.cpp
|
|
||||||
src/Syncers/Download.cpp
|
|
||||||
src/Syncers/RetrieveRecords.cpp
|
|
||||||
src/Syncers/Upload.cpp
|
|
||||||
src/Utilities/Conversions.cpp
|
|
||||||
)
|
|
||||||
set(HEADERS
|
|
||||||
include/Managers/ActionManager.h
|
|
||||||
include/Managers/CommitManager.h
|
|
||||||
include/Managers/FileManager.h
|
|
||||||
include/Managers/TokenManager.h
|
|
||||||
include/Managers/UserManager.h
|
|
||||||
include/Models/API.h
|
|
||||||
include/Models/Flags.h
|
|
||||||
include/Models/IcarusAction.h
|
|
||||||
include/Models/Song.h
|
|
||||||
include/Models/Token.h
|
|
||||||
include/Models/UploadForm.h
|
|
||||||
include/Models/User.h
|
|
||||||
include/Parsers/APIParser.h
|
|
||||||
include/Syncers/Delete.h
|
|
||||||
include/Syncers/Download.h
|
|
||||||
include/Syncers/RetrieveRecords.h
|
|
||||||
include/Syncers/SyncerBase.h
|
|
||||||
include/Syncers/Upload.h
|
|
||||||
include/Utilities/Conversions.h
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
hunter_add_package(nlohmann_json)
|
|
||||||
find_package(nlohmann_json CONFIG REQUIRED)
|
|
||||||
|
|
||||||
hunter_add_package(cpr)
|
|
||||||
find_package(cpr CONFIG REQUIRED)
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(icd ${SOURCES} ${HEADERS})
|
|
||||||
target_link_libraries(icd PUBLIC nlohmann_json::nlohmann_json cpr::cpr)
|
|
||||||
include_directories(include/)
|
|
||||||
Generated
+2425
File diff suppressed because it is too large
Load Diff
+17
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "icarus-dm"
|
||||||
|
version = "0.10.0"
|
||||||
|
rust-version = "1.95"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[dependencies]
|
||||||
|
futures = { version = "0.3.32" }
|
||||||
|
http = { version = "1.4.0" }
|
||||||
|
reqwest = { version = "0.13.3", features = ["json", "blocking", "multipart", "stream"] }
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
serde_json = "1.0.149"
|
||||||
|
tokio = { version = "1.52", features = ["full"] }
|
||||||
|
tokio-util = { version = "0.7.18", features = ["codec"] }
|
||||||
|
uuid = { version = "1.23.1", features = ["v4", "serde"] }
|
||||||
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.11.1" }
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019 Kun Deng
|
Copyright (c) 2026 Kun Deng
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,47 +1,80 @@
|
|||||||
# IcarusDownloadManager
|
# IcarusDownloadManager
|
||||||
|
|
||||||
IcarusDownloadManager is a Linux UI software client application that has the feature of uploading and downloading songs from the [Icarus](https://github.com/amazing-username/Icarus) Music Server.
|
IcarusDownloadManager is a CLI software client application that has the feature of uploading and downloading songs from the [Icarus](https://github.com/kdeng00/Icarus) Music Server.
|
||||||
|
|
||||||
|
|
||||||
### Getting Started
|
|
||||||
|
|
||||||
Build the project:
|
|
||||||
|
|
||||||
```
|
|
||||||
export HUNTER_ROOT=/path/to/download/hunter/files/for/dependencies
|
|
||||||
mkdir _build
|
|
||||||
cd _build
|
|
||||||
cmake -H. -B_builds -DHUNTER_STATUS_DEBUG=ON -DCMAKE_BUILD_TYPE=DEBUG
|
|
||||||
cmake --build _builds --config Debug
|
|
||||||
make
|
|
||||||
```
|
|
||||||
|
|
||||||
The program has been built and can be executed by the binary file *icd*
|
|
||||||
|
|
||||||
|
|
||||||
## Built With
|
## Built With
|
||||||
|
|
||||||
* C++
|
* Rust
|
||||||
* CMake
|
* Cargo
|
||||||
* GCC
|
* futures
|
||||||
* [Hunter](https://github.com/ruslo/hunter)
|
* http
|
||||||
* libCurl
|
* reqwst
|
||||||
* [json](https://github.com/nlohmann/json)
|
* serde
|
||||||
* [cpr](http://whoshuu.github.io/cpr/)
|
* serde_json
|
||||||
|
* tokio
|
||||||
|
* tokio-util
|
||||||
|
* icarus_models
|
||||||
|
|
||||||
|
|
||||||
|
### Getting Started
|
||||||
|
|
||||||
|
Clone the repo
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
git clone git@github.com:kdeng00/IcarusDownloadManager.git
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Build the project:
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
cd IcarusDownloadManager
|
||||||
|
cargo build
|
||||||
|
```
|
||||||
|
|
||||||
|
Even though this project is open source, there are some libraries that are closed source (may be opened later).
|
||||||
|
In order to successfully build it, your ssh public key would be needed to add to the closed libraries. If you
|
||||||
|
have interest, something could be worked out to provide access.
|
||||||
|
|
||||||
|
The program has been built and can be executed by the binary file *icarus-dm*. For information on how to use icarua-dm, merely execute the program without any command line arguments.
|
||||||
|
|
||||||
|
### Downloading Song
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
icarus-dm download -u spacecadet -p stellar40 -h https://icarus.com -ha https://auth.icarus.com -b e8407fc6-edd2-44c1-993f-08dd7324d91a
|
||||||
|
```
|
||||||
|
|
||||||
|
### Uploading Song with metadata
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -ha https://auth.icarus.com -s /path/of/song.flac -t 1 -m /path/to/metadata/config/collection.json -ca /path/to/cover/art/image.png
|
||||||
|
```
|
||||||
|
|
||||||
|
### Uploading Song with metadata from directory
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -ha https://auth.icarus.com -smca /path/where/songs/and/metadata/exists/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Retrieving Song in json
|
||||||
|
|
||||||
|
```Bash
|
||||||
|
icarus-dm retrieve -u spacecadet -p stellar40 -h https://icarus.com -ha https://auth.icarus.com -rt songs
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deleting Song
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
icarus-dm delete -u spacecadet -p stellar40 -h https://icarus.com -ha https://auth.icarus.com -D e8407fc6-edd2-44c1-993f-08dd7324d91a
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests to the project.
|
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests to the project.
|
||||||
|
|
||||||
## Versioning
|
|
||||||
|
|
||||||
[v0.1.0](https://github.com/amazing-username/IcarusDownloadManager/releases/tag/0.1.0)
|
|
||||||
|
|
||||||
## Authors
|
|
||||||
|
|
||||||
* **Kun Deng** - [amazing-username](https://github.com/amazing-username)
|
|
||||||
|
|
||||||
See also the list of [contributors](https://github.com/amazing-username/Icarus/graphs/contributors) who participated in this project.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1,528 +0,0 @@
|
|||||||
# Copyright (c) 2013-2019, Ruslan Baratov
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
|
||||||
# modification, are permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
# list of conditions and the following disclaimer.
|
|
||||||
#
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
# this list of conditions and the following disclaimer in the documentation
|
|
||||||
# and/or other materials provided with the distribution.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
# This is a gate file to Hunter package manager.
|
|
||||||
# Include this file using `include` command and add package you need, example:
|
|
||||||
#
|
|
||||||
# cmake_minimum_required(VERSION 3.2)
|
|
||||||
#
|
|
||||||
# include("cmake/HunterGate.cmake")
|
|
||||||
# HunterGate(
|
|
||||||
# URL "https://github.com/path/to/hunter/archive.tar.gz"
|
|
||||||
# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d"
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# project(MyProject)
|
|
||||||
#
|
|
||||||
# hunter_add_package(Foo)
|
|
||||||
# hunter_add_package(Boo COMPONENTS Bar Baz)
|
|
||||||
#
|
|
||||||
# Projects:
|
|
||||||
# * https://github.com/hunter-packages/gate/
|
|
||||||
# * https://github.com/ruslo/hunter
|
|
||||||
|
|
||||||
option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
|
|
||||||
|
|
||||||
if(HUNTER_ENABLED)
|
|
||||||
if(CMAKE_VERSION VERSION_LESS "3.2")
|
|
||||||
message(
|
|
||||||
FATAL_ERROR
|
|
||||||
"At least CMake version 3.2 required for Hunter dependency management."
|
|
||||||
" Update CMake or set HUNTER_ENABLED to OFF."
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(CMakeParseArguments) # cmake_parse_arguments
|
|
||||||
|
|
||||||
option(HUNTER_STATUS_PRINT "Print working status" ON)
|
|
||||||
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
|
|
||||||
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)
|
|
||||||
|
|
||||||
set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors")
|
|
||||||
|
|
||||||
function(hunter_gate_status_print)
|
|
||||||
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
|
|
||||||
foreach(print_message ${ARGV})
|
|
||||||
message(STATUS "[hunter] ${print_message}")
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_status_debug)
|
|
||||||
if(HUNTER_STATUS_DEBUG)
|
|
||||||
foreach(print_message ${ARGV})
|
|
||||||
string(TIMESTAMP timestamp)
|
|
||||||
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}")
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_error_page error_page)
|
|
||||||
message("------------------------------ ERROR ------------------------------")
|
|
||||||
message(" ${HUNTER_ERROR_PAGE}/${error_page}.html")
|
|
||||||
message("-------------------------------------------------------------------")
|
|
||||||
message("")
|
|
||||||
message(FATAL_ERROR "")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_internal_error)
|
|
||||||
message("")
|
|
||||||
foreach(print_message ${ARGV})
|
|
||||||
message("[hunter ** INTERNAL **] ${print_message}")
|
|
||||||
endforeach()
|
|
||||||
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
|
|
||||||
message("")
|
|
||||||
hunter_gate_error_page("error.internal")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_fatal_error)
|
|
||||||
cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}")
|
|
||||||
if("${hunter_ERROR_PAGE}" STREQUAL "")
|
|
||||||
hunter_gate_internal_error("Expected ERROR_PAGE")
|
|
||||||
endif()
|
|
||||||
message("")
|
|
||||||
foreach(x ${hunter_UNPARSED_ARGUMENTS})
|
|
||||||
message("[hunter ** FATAL ERROR **] ${x}")
|
|
||||||
endforeach()
|
|
||||||
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
|
|
||||||
message("")
|
|
||||||
hunter_gate_error_page("${hunter_ERROR_PAGE}")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_user_error)
|
|
||||||
hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_self root version sha1 result)
|
|
||||||
string(COMPARE EQUAL "${root}" "" is_bad)
|
|
||||||
if(is_bad)
|
|
||||||
hunter_gate_internal_error("root is empty")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(COMPARE EQUAL "${version}" "" is_bad)
|
|
||||||
if(is_bad)
|
|
||||||
hunter_gate_internal_error("version is empty")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(COMPARE EQUAL "${sha1}" "" is_bad)
|
|
||||||
if(is_bad)
|
|
||||||
hunter_gate_internal_error("sha1 is empty")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(SUBSTRING "${sha1}" 0 7 archive_id)
|
|
||||||
|
|
||||||
set(
|
|
||||||
hunter_self
|
|
||||||
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
|
|
||||||
)
|
|
||||||
|
|
||||||
set("${result}" "${hunter_self}" PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
# Set HUNTER_GATE_ROOT cmake variable to suitable value.
|
|
||||||
function(hunter_gate_detect_root)
|
|
||||||
# Check CMake variable
|
|
||||||
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty)
|
|
||||||
if(not_empty)
|
|
||||||
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE)
|
|
||||||
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Check environment variable
|
|
||||||
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty)
|
|
||||||
if(not_empty)
|
|
||||||
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE)
|
|
||||||
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Check HOME environment variable
|
|
||||||
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result)
|
|
||||||
if(result)
|
|
||||||
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE)
|
|
||||||
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
|
|
||||||
if(WIN32)
|
|
||||||
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result)
|
|
||||||
if(result)
|
|
||||||
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE)
|
|
||||||
hunter_gate_status_debug(
|
|
||||||
"HUNTER_ROOT set using SYSTEMDRIVE environment variable"
|
|
||||||
)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result)
|
|
||||||
if(result)
|
|
||||||
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE)
|
|
||||||
hunter_gate_status_debug(
|
|
||||||
"HUNTER_ROOT set using USERPROFILE environment variable"
|
|
||||||
)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
hunter_gate_fatal_error(
|
|
||||||
"Can't detect HUNTER_ROOT"
|
|
||||||
ERROR_PAGE "error.detect.hunter.root"
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(hunter_gate_download dir)
|
|
||||||
string(
|
|
||||||
COMPARE
|
|
||||||
NOTEQUAL
|
|
||||||
"$ENV{HUNTER_DISABLE_AUTOINSTALL}"
|
|
||||||
""
|
|
||||||
disable_autoinstall
|
|
||||||
)
|
|
||||||
if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL)
|
|
||||||
hunter_gate_fatal_error(
|
|
||||||
"Hunter not found in '${dir}'"
|
|
||||||
"Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'"
|
|
||||||
"Settings:"
|
|
||||||
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
|
|
||||||
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
|
|
||||||
ERROR_PAGE "error.run.install"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
string(COMPARE EQUAL "${dir}" "" is_bad)
|
|
||||||
if(is_bad)
|
|
||||||
hunter_gate_internal_error("Empty 'dir' argument")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad)
|
|
||||||
if(is_bad)
|
|
||||||
hunter_gate_internal_error("HUNTER_GATE_SHA1 empty")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad)
|
|
||||||
if(is_bad)
|
|
||||||
hunter_gate_internal_error("HUNTER_GATE_URL empty")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(done_location "${dir}/DONE")
|
|
||||||
set(sha1_location "${dir}/SHA1")
|
|
||||||
|
|
||||||
set(build_dir "${dir}/Build")
|
|
||||||
set(cmakelists "${dir}/CMakeLists.txt")
|
|
||||||
|
|
||||||
hunter_gate_status_debug("Locking directory: ${dir}")
|
|
||||||
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
|
|
||||||
hunter_gate_status_debug("Lock done")
|
|
||||||
|
|
||||||
if(EXISTS "${done_location}")
|
|
||||||
# while waiting for lock other instance can do all the job
|
|
||||||
hunter_gate_status_debug("File '${done_location}' found, skip install")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(REMOVE_RECURSE "${build_dir}")
|
|
||||||
file(REMOVE_RECURSE "${cmakelists}")
|
|
||||||
|
|
||||||
file(MAKE_DIRECTORY "${build_dir}") # check directory permissions
|
|
||||||
|
|
||||||
# Disabling languages speeds up a little bit, reduces noise in the output
|
|
||||||
# and avoids path too long windows error
|
|
||||||
file(
|
|
||||||
WRITE
|
|
||||||
"${cmakelists}"
|
|
||||||
"cmake_minimum_required(VERSION 3.2)\n"
|
|
||||||
"project(HunterDownload LANGUAGES NONE)\n"
|
|
||||||
"include(ExternalProject)\n"
|
|
||||||
"ExternalProject_Add(\n"
|
|
||||||
" Hunter\n"
|
|
||||||
" URL\n"
|
|
||||||
" \"${HUNTER_GATE_URL}\"\n"
|
|
||||||
" URL_HASH\n"
|
|
||||||
" SHA1=${HUNTER_GATE_SHA1}\n"
|
|
||||||
" DOWNLOAD_DIR\n"
|
|
||||||
" \"${dir}\"\n"
|
|
||||||
" TLS_VERIFY\n"
|
|
||||||
" ${HUNTER_TLS_VERIFY}\n"
|
|
||||||
" SOURCE_DIR\n"
|
|
||||||
" \"${dir}/Unpacked\"\n"
|
|
||||||
" CONFIGURE_COMMAND\n"
|
|
||||||
" \"\"\n"
|
|
||||||
" BUILD_COMMAND\n"
|
|
||||||
" \"\"\n"
|
|
||||||
" INSTALL_COMMAND\n"
|
|
||||||
" \"\"\n"
|
|
||||||
")\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(HUNTER_STATUS_DEBUG)
|
|
||||||
set(logging_params "")
|
|
||||||
else()
|
|
||||||
set(logging_params OUTPUT_QUIET)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
hunter_gate_status_debug("Run generate")
|
|
||||||
|
|
||||||
# Need to add toolchain file too.
|
|
||||||
# Otherwise on Visual Studio + MDD this will fail with error:
|
|
||||||
# "Could not find an appropriate version of the Windows 10 SDK installed on this machine"
|
|
||||||
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
|
||||||
get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE)
|
|
||||||
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}")
|
|
||||||
else()
|
|
||||||
# 'toolchain_arg' can't be empty
|
|
||||||
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make)
|
|
||||||
if(no_make)
|
|
||||||
set(make_arg "")
|
|
||||||
else()
|
|
||||||
# Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM
|
|
||||||
set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND
|
|
||||||
"${CMAKE_COMMAND}"
|
|
||||||
"-H${dir}"
|
|
||||||
"-B${build_dir}"
|
|
||||||
"-G${CMAKE_GENERATOR}"
|
|
||||||
"${toolchain_arg}"
|
|
||||||
${make_arg}
|
|
||||||
WORKING_DIRECTORY "${dir}"
|
|
||||||
RESULT_VARIABLE download_result
|
|
||||||
${logging_params}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT download_result EQUAL 0)
|
|
||||||
hunter_gate_internal_error(
|
|
||||||
"Configure project failed."
|
|
||||||
"To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}"
|
|
||||||
"In directory ${dir}"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
hunter_gate_status_print(
|
|
||||||
"Initializing Hunter workspace (${HUNTER_GATE_SHA1})"
|
|
||||||
" ${HUNTER_GATE_URL}"
|
|
||||||
" -> ${dir}"
|
|
||||||
)
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${CMAKE_COMMAND}" --build "${build_dir}"
|
|
||||||
WORKING_DIRECTORY "${dir}"
|
|
||||||
RESULT_VARIABLE download_result
|
|
||||||
${logging_params}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT download_result EQUAL 0)
|
|
||||||
hunter_gate_internal_error("Build project failed")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(REMOVE_RECURSE "${build_dir}")
|
|
||||||
file(REMOVE_RECURSE "${cmakelists}")
|
|
||||||
|
|
||||||
file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}")
|
|
||||||
file(WRITE "${done_location}" "DONE")
|
|
||||||
|
|
||||||
hunter_gate_status_debug("Finished")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
# Must be a macro so master file 'cmake/Hunter' can
|
|
||||||
# apply all variables easily just by 'include' command
|
|
||||||
# (otherwise PARENT_SCOPE magic needed)
|
|
||||||
macro(HunterGate)
|
|
||||||
if(HUNTER_GATE_DONE)
|
|
||||||
# variable HUNTER_GATE_DONE set explicitly for external project
|
|
||||||
# (see `hunter_download`)
|
|
||||||
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# First HunterGate command will init Hunter, others will be ignored
|
|
||||||
get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET)
|
|
||||||
|
|
||||||
if(NOT HUNTER_ENABLED)
|
|
||||||
# Empty function to avoid error "unknown function"
|
|
||||||
function(hunter_add_package)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
set(
|
|
||||||
_hunter_gate_disabled_mode_dir
|
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode"
|
|
||||||
)
|
|
||||||
if(EXISTS "${_hunter_gate_disabled_mode_dir}")
|
|
||||||
hunter_gate_status_debug(
|
|
||||||
"Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}"
|
|
||||||
)
|
|
||||||
list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}")
|
|
||||||
endif()
|
|
||||||
elseif(_hunter_gate_done)
|
|
||||||
hunter_gate_status_debug("Secondary HunterGate (use old settings)")
|
|
||||||
hunter_gate_self(
|
|
||||||
"${HUNTER_CACHED_ROOT}"
|
|
||||||
"${HUNTER_VERSION}"
|
|
||||||
"${HUNTER_SHA1}"
|
|
||||||
_hunter_self
|
|
||||||
)
|
|
||||||
include("${_hunter_self}/cmake/Hunter")
|
|
||||||
else()
|
|
||||||
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
||||||
|
|
||||||
string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name)
|
|
||||||
if(_have_project_name)
|
|
||||||
hunter_gate_fatal_error(
|
|
||||||
"Please set HunterGate *before* 'project' command. "
|
|
||||||
"Detected project: ${PROJECT_NAME}"
|
|
||||||
ERROR_PAGE "error.huntergate.before.project"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
cmake_parse_arguments(
|
|
||||||
HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV}
|
|
||||||
)
|
|
||||||
|
|
||||||
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1)
|
|
||||||
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url)
|
|
||||||
string(
|
|
||||||
COMPARE
|
|
||||||
NOTEQUAL
|
|
||||||
"${HUNTER_GATE_UNPARSED_ARGUMENTS}"
|
|
||||||
""
|
|
||||||
_have_unparsed
|
|
||||||
)
|
|
||||||
string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global)
|
|
||||||
string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath)
|
|
||||||
|
|
||||||
if(_have_unparsed)
|
|
||||||
hunter_gate_user_error(
|
|
||||||
"HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
if(_empty_sha1)
|
|
||||||
hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory")
|
|
||||||
endif()
|
|
||||||
if(_empty_url)
|
|
||||||
hunter_gate_user_error("URL suboption of HunterGate is mandatory")
|
|
||||||
endif()
|
|
||||||
if(_have_global)
|
|
||||||
if(HUNTER_GATE_LOCAL)
|
|
||||||
hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)")
|
|
||||||
endif()
|
|
||||||
if(_have_filepath)
|
|
||||||
hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
if(HUNTER_GATE_LOCAL)
|
|
||||||
if(_have_global)
|
|
||||||
hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)")
|
|
||||||
endif()
|
|
||||||
if(_have_filepath)
|
|
||||||
hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
if(_have_filepath)
|
|
||||||
if(_have_global)
|
|
||||||
hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)")
|
|
||||||
endif()
|
|
||||||
if(HUNTER_GATE_LOCAL)
|
|
||||||
hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
hunter_gate_detect_root() # set HUNTER_GATE_ROOT
|
|
||||||
|
|
||||||
# Beautify path, fix probable problems with windows path slashes
|
|
||||||
get_filename_component(
|
|
||||||
HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE
|
|
||||||
)
|
|
||||||
hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}")
|
|
||||||
if(NOT HUNTER_ALLOW_SPACES_IN_PATH)
|
|
||||||
string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces)
|
|
||||||
if(NOT _contain_spaces EQUAL -1)
|
|
||||||
hunter_gate_fatal_error(
|
|
||||||
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
|
|
||||||
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
|
|
||||||
"(Use at your own risk!)"
|
|
||||||
ERROR_PAGE "error.spaces.in.hunter.root"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(
|
|
||||||
REGEX
|
|
||||||
MATCH
|
|
||||||
"[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*"
|
|
||||||
HUNTER_GATE_VERSION
|
|
||||||
"${HUNTER_GATE_URL}"
|
|
||||||
)
|
|
||||||
string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty)
|
|
||||||
if(_is_empty)
|
|
||||||
set(HUNTER_GATE_VERSION "unknown")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
hunter_gate_self(
|
|
||||||
"${HUNTER_GATE_ROOT}"
|
|
||||||
"${HUNTER_GATE_VERSION}"
|
|
||||||
"${HUNTER_GATE_SHA1}"
|
|
||||||
_hunter_self
|
|
||||||
)
|
|
||||||
|
|
||||||
set(_master_location "${_hunter_self}/cmake/Hunter")
|
|
||||||
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
|
|
||||||
set(_done_location "${_archive_id_location}/DONE")
|
|
||||||
set(_sha1_location "${_archive_id_location}/SHA1")
|
|
||||||
|
|
||||||
# Check Hunter already downloaded by HunterGate
|
|
||||||
if(NOT EXISTS "${_done_location}")
|
|
||||||
hunter_gate_download("${_archive_id_location}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT EXISTS "${_done_location}")
|
|
||||||
hunter_gate_internal_error("hunter_gate_download failed")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT EXISTS "${_sha1_location}")
|
|
||||||
hunter_gate_internal_error("${_sha1_location} not found")
|
|
||||||
endif()
|
|
||||||
file(READ "${_sha1_location}" _sha1_value)
|
|
||||||
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
|
|
||||||
if(NOT _is_equal)
|
|
||||||
hunter_gate_internal_error(
|
|
||||||
"Short SHA1 collision:"
|
|
||||||
" ${_sha1_value} (from ${_sha1_location})"
|
|
||||||
" ${HUNTER_GATE_SHA1} (HunterGate)"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
if(NOT EXISTS "${_master_location}")
|
|
||||||
hunter_gate_user_error(
|
|
||||||
"Master file not found:"
|
|
||||||
" ${_master_location}"
|
|
||||||
"try to update Hunter/HunterGate"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
include("${_master_location}")
|
|
||||||
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
|
|
||||||
endif()
|
|
||||||
endmacro()
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#ifndef ACTIONMANAGER_H_
|
|
||||||
#define ACTIONMANAGER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
#include<array>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
#include"Models/Flags.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
class ActionManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ActionManager(char**, int);
|
|
||||||
|
|
||||||
Models::IcarusAction retrieveIcarusAction() const;
|
|
||||||
private:
|
|
||||||
bool isNumber(std::string);
|
|
||||||
|
|
||||||
void initialize();
|
|
||||||
void validateFlags();
|
|
||||||
|
|
||||||
std::vector<std::string> parsedFlags();
|
|
||||||
|
|
||||||
void printAction();
|
|
||||||
void printFlags();
|
|
||||||
|
|
||||||
std::string action;
|
|
||||||
std::array<std::string, 4> supportedActions{
|
|
||||||
"download", "upload", "retrieve", "delete"
|
|
||||||
};
|
|
||||||
std::array<std::string, 11> supportedFlags{
|
|
||||||
"-u", "-p", "-t", "-h", "-s", "-sd",
|
|
||||||
"-sr", "-d", "-D", "-b", "-rt"
|
|
||||||
};
|
|
||||||
std::vector<Models::Flags> flags;
|
|
||||||
char **params;
|
|
||||||
int paramCount;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef COMMITMANAGER_H_
|
|
||||||
#define COMMITMANAGER_H_
|
|
||||||
|
|
||||||
#include<map>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
class CommitManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommitManager(Models::IcarusAction&);
|
|
||||||
|
|
||||||
void commitAction();
|
|
||||||
|
|
||||||
enum RetrieveTypes
|
|
||||||
{
|
|
||||||
songs
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
Models::Token parseToken(Models::API);
|
|
||||||
|
|
||||||
void deleteSong();
|
|
||||||
void downloadSong();
|
|
||||||
void retrieveObjects();
|
|
||||||
void uploadSong();
|
|
||||||
|
|
||||||
enum ActionValues
|
|
||||||
{
|
|
||||||
deleteAct,
|
|
||||||
downloadAct,
|
|
||||||
retrieveAct,
|
|
||||||
uploadAct
|
|
||||||
};
|
|
||||||
|
|
||||||
std::map<std::string, ActionValues> mapActions{
|
|
||||||
{"delete", deleteAct}, {"download", downloadAct},
|
|
||||||
{"retrieve", retrieveAct},
|
|
||||||
{"upload", uploadAct}
|
|
||||||
};
|
|
||||||
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef FILEMANAGER_H_
|
|
||||||
#define FILEMANAGER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
class FileManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileManager();
|
|
||||||
FileManager(std::string);
|
|
||||||
|
|
||||||
void saveFile(std::string);
|
|
||||||
void modifyFilePath(std::string);
|
|
||||||
|
|
||||||
char* retrieveFileBuffer() const;
|
|
||||||
int retrieveFileBufferLength() const;
|
|
||||||
private:
|
|
||||||
void readFile();
|
|
||||||
|
|
||||||
std::string filePath;
|
|
||||||
char* fileBuffer;
|
|
||||||
bool fileRead;
|
|
||||||
int fileBufferLength;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef TOKENMANAGER_H_
|
|
||||||
#define TOKENMANAGER_H_
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
#include"Models/User.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
class TokenManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TokenManager(const Models::User&);
|
|
||||||
TokenManager(const Models::User&, Models::API&);
|
|
||||||
|
|
||||||
Models::Token requestToken();
|
|
||||||
private:
|
|
||||||
Models::API api;
|
|
||||||
Models::User user;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#ifndef USERMANAGER_H_
|
|
||||||
#define USERMANAGER_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
#include"Models/User.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
class UserManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
UserManager(Models::User);
|
|
||||||
UserManager(const Models::IcarusAction);
|
|
||||||
|
|
||||||
Models::User retrieveUser() const;
|
|
||||||
private:
|
|
||||||
void parseUserFromActions();
|
|
||||||
|
|
||||||
Models::User user;
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef API_H_
|
|
||||||
#define API_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct API
|
|
||||||
{
|
|
||||||
std::string url;
|
|
||||||
std::string endpoint;
|
|
||||||
std::string version;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef FLAGS_H_
|
|
||||||
#define FLAGS_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct Flags
|
|
||||||
{
|
|
||||||
std::string flag;
|
|
||||||
std::string value;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef ICARUSACTION_H_
|
|
||||||
#define ICARUSACTION_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
#include"Flags.h"
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct IcarusAction
|
|
||||||
{
|
|
||||||
std::string action;
|
|
||||||
std::vector<Flags> flags;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef SONG_H_
|
|
||||||
#define SONG_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct Song
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
std::string title;
|
|
||||||
std::string artist;
|
|
||||||
std::string album;
|
|
||||||
std::string genre;
|
|
||||||
int year;
|
|
||||||
int duration;
|
|
||||||
int track;
|
|
||||||
std::string data;
|
|
||||||
std::string songPath;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef TOKEN_H_
|
|
||||||
#define TOKEN_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct Token
|
|
||||||
{
|
|
||||||
std::string accessToken;
|
|
||||||
std::string tokenType;
|
|
||||||
int expiration;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef UPLOADFORM_H_
|
|
||||||
#define UPLOADFORM_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct UploadForm
|
|
||||||
{
|
|
||||||
std::string url;
|
|
||||||
std::string filePath;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef USER_H_
|
|
||||||
#define USER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct User
|
|
||||||
{
|
|
||||||
std::string username;
|
|
||||||
std::string password;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef APIPARSER_H_
|
|
||||||
#define APIPARSER_H_
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
|
|
||||||
namespace Parsers
|
|
||||||
{
|
|
||||||
class APIParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
APIParser(Models::IcarusAction);
|
|
||||||
|
|
||||||
Models::API retrieveAPI() const;
|
|
||||||
private:
|
|
||||||
void parseAPI();
|
|
||||||
|
|
||||||
Models::API api;
|
|
||||||
Models::IcarusAction icaAct;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef DELETE_H_
|
|
||||||
#define DELETE_H_
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
|
|
||||||
#include"SyncerBase.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
class Delete : SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Delete(Models::API);
|
|
||||||
|
|
||||||
void deleteSong(const Models::Token, Models::Song);
|
|
||||||
private:
|
|
||||||
std::string retrieveUrl(Models::Song);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
#ifndef DOWNLOAD_H_
|
|
||||||
#define DOWNLOAD_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
|
|
||||||
#include"SyncerBase.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
class Download : SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Download();
|
|
||||||
Download(Models::API);
|
|
||||||
Download(std::string);
|
|
||||||
|
|
||||||
void downloadSong(const Models::Token token, Models::Song);
|
|
||||||
private:
|
|
||||||
std::string retrieveUrl(Models::Song);
|
|
||||||
|
|
||||||
std::string downloadFilePath;
|
|
||||||
void saveSong(Models::Song&);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#ifndef RETRIEVERECORDS_H_
|
|
||||||
#define RETRIEVERECORDS_H_
|
|
||||||
|
|
||||||
#include "Managers/CommitManager.h"
|
|
||||||
#include "Models/API.h"
|
|
||||||
#include "Models/Token.h"
|
|
||||||
#include "Syncers/SyncerBase.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
class RetrieveRecords: public SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RetrieveRecords();
|
|
||||||
RetrieveRecords(Models::API, Models::Token);
|
|
||||||
|
|
||||||
void retrieve(Managers::CommitManager::RetrieveTypes);
|
|
||||||
private:
|
|
||||||
void fetchSongs();
|
|
||||||
|
|
||||||
Models::API api;
|
|
||||||
Models::Token token;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#ifndef SYNCERBASE_H_
|
|
||||||
#define SYNCERBASE_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
class SyncerBase
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
Models::API api;
|
|
||||||
const int OK = 200;
|
|
||||||
const int UNAUTHORIZED = 401;
|
|
||||||
const int NOTFOUND = 404;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
#ifndef UPLOAD_H_
|
|
||||||
#define UPLOAD_H_
|
|
||||||
|
|
||||||
#include<filesystem>
|
|
||||||
#include<string>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
#include<nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include"Managers/FileManager.h"
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
#include"Models/UploadForm.h"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
class Upload
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Upload();
|
|
||||||
Upload(Models::API);
|
|
||||||
|
|
||||||
Models::Song uploadSong(const Models::Token&, Models::Song&);
|
|
||||||
void uploadSongsFromDirectory(const Models::Token&, const std::string&, bool);
|
|
||||||
private:
|
|
||||||
Managers::FileManager fMgr;
|
|
||||||
Models::API api;
|
|
||||||
Models::Song song;
|
|
||||||
|
|
||||||
std::vector<Models::Song> retrieveAllSongsFromDirectory(const std::string&,
|
|
||||||
bool);
|
|
||||||
|
|
||||||
std::string retrieveUrl();
|
|
||||||
|
|
||||||
Models::Song retrieveSongPath(fs::directory_entry&);
|
|
||||||
|
|
||||||
void printSongDetails();
|
|
||||||
void printSongDetails(std::vector<Models::Song>&);
|
|
||||||
void printJsonData(nlohmann::json);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#ifndef ABOUTWINDOW_H_
|
|
||||||
#define ABOUTWINDOW_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QDockWidget>
|
|
||||||
#include<QLabel>
|
|
||||||
#include<QPushButton>
|
|
||||||
#include<QWidget>
|
|
||||||
|
|
||||||
#include"UI/CommonWindow.h"
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
class AboutWindow: public QDialog, public CommonWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
AboutWindow(QWidget* parent=0);
|
|
||||||
~AboutWindow() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void connections();
|
|
||||||
void setupWindow();
|
|
||||||
|
|
||||||
std::unique_ptr<QLabel> appName;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void closeWindow();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#ifndef COMMONWINDOW_H_
|
|
||||||
#define COMMONWINDOW_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QHBoxLayout>
|
|
||||||
#include<QVBoxLayout>
|
|
||||||
#include<QComboBox>
|
|
||||||
#include<QPushButton>
|
|
||||||
|
|
||||||
|
|
||||||
class CommonWindow
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommonWindow() = default;
|
|
||||||
~CommonWindow() = default;
|
|
||||||
protected:
|
|
||||||
virtual void connections()=0;
|
|
||||||
std::unique_ptr<QComboBox> selectionBoxQt;
|
|
||||||
std::unique_ptr<QPushButton> actionButtonQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> mainLayoutQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> subLayoutOneQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
|
||||||
int windowHeight, windowWidth;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#ifndef MAINWINDOW_H_
|
|
||||||
#define MAINWINDOW_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QAction>
|
|
||||||
#include<QComboBox>
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QDockWidget>
|
|
||||||
#include<QLabel>
|
|
||||||
#include<QMenu>
|
|
||||||
#include<QMenuBar>
|
|
||||||
#include<QMainWindow>
|
|
||||||
#include<QPushButton>
|
|
||||||
#include<QStackedWidget>
|
|
||||||
#include<QTextEdit>
|
|
||||||
#include<QWidget>
|
|
||||||
|
|
||||||
#include"UI/CommonWindow.h"
|
|
||||||
#include"UI/AboutWindow.h"
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
class MainWindow: public QMainWindow, public CommonWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
MainWindow();
|
|
||||||
~MainWindow() = default;
|
|
||||||
private:
|
|
||||||
void configureDownloadSection();
|
|
||||||
void configureUploadSection();
|
|
||||||
void configureWindowDimensions();
|
|
||||||
void configureWindowProperties();
|
|
||||||
void connections();
|
|
||||||
void createMenus();
|
|
||||||
void setupMainWidget();
|
|
||||||
void setupMainWindow();
|
|
||||||
void setupWindowLists();
|
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<QStackedWidget> widgetStack;
|
|
||||||
|
|
||||||
std::unique_ptr<QVBoxLayout> stackLayout;
|
|
||||||
|
|
||||||
std::unique_ptr<QHBoxLayout> urlPortion;
|
|
||||||
std::unique_ptr<QHBoxLayout> songPathPortion;
|
|
||||||
|
|
||||||
std::unique_ptr<QWidget> mainWidgetQt;
|
|
||||||
std::unique_ptr<QWidget> uploadSongWidgetQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QComboBox> windowComboBox;
|
|
||||||
|
|
||||||
std::unique_ptr<QPushButton> uploadSongQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QTextEdit> urlQt;
|
|
||||||
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QLabel> urlLabel;
|
|
||||||
std::unique_ptr<QLabel> songPath;
|
|
||||||
|
|
||||||
std::unique_ptr<QMenu> fileMenuQt;
|
|
||||||
std::unique_ptr<QMenu> editMenuQt;
|
|
||||||
std::unique_ptr<QMenu> helpMenuQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QAction> closeApplicationQt;
|
|
||||||
std::unique_ptr<QAction> aboutApplicationQt;
|
|
||||||
|
|
||||||
std::unique_ptr<AboutWindow> aboutWindow;
|
|
||||||
signals:
|
|
||||||
private slots:
|
|
||||||
void uploadSong();
|
|
||||||
void exitApplication();
|
|
||||||
void displaySoftwareInformation();
|
|
||||||
void setCurrentIndex(int);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#ifndef CONVERSIONS_H_
|
|
||||||
#define CONVERSIONS_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Utilities
|
|
||||||
{
|
|
||||||
class Conversions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Conversions();
|
|
||||||
|
|
||||||
void initializeValues();
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void printValue(T);
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
cmake -H. -B_builds -DHUNTER_STATUS_DEBUG=ON -DCMAKE_BUILD_TYPE=DEBUG
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
cmake --build _builds --config Debug
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
cmake --build _builds --config Release
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Managers/ActionManager.h"
|
|
||||||
#include"Managers/CommitManager.h"
|
|
||||||
|
|
||||||
using std::cin;
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Managers::ActionManager;
|
|
||||||
using Managers::CommitManager;
|
|
||||||
|
|
||||||
void printHelp()
|
|
||||||
{
|
|
||||||
cout<<"icd [Action] [flag]\n\n";
|
|
||||||
|
|
||||||
cout<<"Actions\n";
|
|
||||||
cout<<"download\n";
|
|
||||||
cout<<"upload\n";
|
|
||||||
cout<<"retrieve\n";
|
|
||||||
cout<<"delete\n\n";
|
|
||||||
|
|
||||||
cout<<"Flags\n";
|
|
||||||
cout<<"Required for all actions\n";
|
|
||||||
cout<<"-u username\n";
|
|
||||||
cout<<"-p password\n";
|
|
||||||
cout<<"-h host\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for upload\n";
|
|
||||||
cout<<"-s path of song\n";
|
|
||||||
cout<<"-sd directory where to search for songs to upload (Optional)\n";
|
|
||||||
cout<<"-sr directory where to recursively search for songs to upload (Optional)\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for download\n";
|
|
||||||
cout<<"-b song id\n";
|
|
||||||
cout<<"-d path to download song (Optional)\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for retrieving records\n";
|
|
||||||
cout<<"-rt retrieve type (songs is only accepted)\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for deleting a song\n";
|
|
||||||
cout<<"-D song id\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
printHelp();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionManager actMgr{argv, argc};
|
|
||||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
|
||||||
|
|
||||||
CommitManager commitMgr{chosenAction};
|
|
||||||
commitMgr.commitAction();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
#include"Managers/ActionManager.h"
|
|
||||||
|
|
||||||
#include<algorithm>
|
|
||||||
#include<iostream>
|
|
||||||
#include<utility>
|
|
||||||
#include<cstring>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
using Models::Flags;
|
|
||||||
using Models::IcarusAction;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
ActionManager::ActionManager(char **param, int paramCount) :
|
|
||||||
params(std::move(param)), paramCount(paramCount)
|
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
IcarusAction ActionManager::retrieveIcarusAction() const
|
|
||||||
{
|
|
||||||
auto icarusAction = IcarusAction{};
|
|
||||||
icarusAction.flags = flags;
|
|
||||||
icarusAction.action = action;
|
|
||||||
|
|
||||||
return icarusAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ActionManager::isNumber(string val)
|
|
||||||
{
|
|
||||||
return !val.empty() && std::find_if(val.begin(),
|
|
||||||
val.end(), [](char c)
|
|
||||||
{
|
|
||||||
return !std::isdigit(c);
|
|
||||||
}) == val.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionManager::initialize()
|
|
||||||
{
|
|
||||||
validateFlags();
|
|
||||||
|
|
||||||
action = std::move(string{params[1]});
|
|
||||||
transform(action.begin(), action.end(),
|
|
||||||
action.begin(), ::tolower);
|
|
||||||
}
|
|
||||||
void ActionManager::validateFlags()
|
|
||||||
{
|
|
||||||
cout<<"Validating flags"<<endl;
|
|
||||||
|
|
||||||
auto flagVals = parsedFlags();
|
|
||||||
|
|
||||||
Flags flg{};
|
|
||||||
|
|
||||||
for (auto flag : flagVals)
|
|
||||||
{
|
|
||||||
if (flag.size() > 3 || isNumber(flag))
|
|
||||||
{
|
|
||||||
flg.value = flag;
|
|
||||||
//cout<<"flag value "<<flg.value<<endl;
|
|
||||||
flags.push_back(flg);
|
|
||||||
flg = Flags{};
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std::any_of(supportedFlags.begin(), supportedFlags.end(),
|
|
||||||
[&](string& val)
|
|
||||||
{
|
|
||||||
return !val.compare(flag);
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
//cout<<"flag "<<flag<<endl;
|
|
||||||
flg.flag = flag;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Action is not valid"<<endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<string> ActionManager::parsedFlags()
|
|
||||||
{
|
|
||||||
auto parsed = vector<string>{};
|
|
||||||
|
|
||||||
for (auto i = 2; i < paramCount; ++i)
|
|
||||||
{
|
|
||||||
parsed.push_back(std::move(*(params + i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
void ActionManager::printAction()
|
|
||||||
{
|
|
||||||
if (action.empty())
|
|
||||||
{
|
|
||||||
printf("Action is empty\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Action is "<<action<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void ActionManager::printFlags()
|
|
||||||
{
|
|
||||||
cout<<"\nPrinting flags..."<<endl;
|
|
||||||
for (auto flag: flags)
|
|
||||||
{
|
|
||||||
cout<<"flag "<<flag.flag<<endl;
|
|
||||||
cout<<"value "<<flag.value<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma Testing
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
#include"Managers/CommitManager.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
#include"Parsers/APIParser.h"
|
|
||||||
#include"Syncers/Delete.h"
|
|
||||||
#include"Syncers/Download.h"
|
|
||||||
#include"Syncers/RetrieveRecords.h"
|
|
||||||
#include"Syncers/Upload.h"
|
|
||||||
|
|
||||||
#include"Managers/TokenManager.h"
|
|
||||||
#include"Managers/UserManager.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::map;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Managers::TokenManager;
|
|
||||||
using Managers::UserManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::Token;
|
|
||||||
using Parsers::APIParser;
|
|
||||||
using Models::IcarusAction;
|
|
||||||
using Syncers::Delete;
|
|
||||||
using Syncers::Download;
|
|
||||||
using Syncers::RetrieveRecords;
|
|
||||||
using Syncers::Upload;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
|
||||||
{ }
|
|
||||||
#pragma Constructors;
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
void CommitManager::commitAction()
|
|
||||||
{
|
|
||||||
auto action = icaAction.action;
|
|
||||||
cout<<"Commiting "<<action<<" action"<<endl;
|
|
||||||
switch (mapActions[action])
|
|
||||||
{
|
|
||||||
case deleteAct:
|
|
||||||
deleteSong();
|
|
||||||
break;
|
|
||||||
case downloadAct:
|
|
||||||
downloadSong();
|
|
||||||
break;
|
|
||||||
case retrieveAct:
|
|
||||||
retrieveObjects();
|
|
||||||
break;
|
|
||||||
case uploadAct:
|
|
||||||
uploadSong();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Token CommitManager::parseToken(API api)
|
|
||||||
{
|
|
||||||
cout<<"fetching token"<<endl;
|
|
||||||
UserManager usrMgr{icaAction};
|
|
||||||
auto user = usrMgr.retrieveUser();
|
|
||||||
|
|
||||||
TokenManager tk{user, api};
|
|
||||||
|
|
||||||
return tk.requestToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommitManager::deleteSong()
|
|
||||||
{
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
|
||||||
Song song{};
|
|
||||||
|
|
||||||
for (auto arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-D") == 0)
|
|
||||||
{
|
|
||||||
song.id = atoi(value.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Delete del{api};
|
|
||||||
cout<<"Deleting song..."<<endl;
|
|
||||||
del.deleteSong(token, song);
|
|
||||||
}
|
|
||||||
void CommitManager::downloadSong()
|
|
||||||
{
|
|
||||||
cout<<"Starting downloading process..."<<endl;
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
|
||||||
Song song{};
|
|
||||||
|
|
||||||
for (auto arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-d") == 0)
|
|
||||||
{
|
|
||||||
song.songPath.assign(arg.value);
|
|
||||||
}
|
|
||||||
if (flag.compare("-b") == 0)
|
|
||||||
{
|
|
||||||
song.id = atoi(value.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Download dnld{api};
|
|
||||||
cout<<"downloading song"<<endl;
|
|
||||||
dnld.downloadSong(token, song);
|
|
||||||
}
|
|
||||||
void CommitManager::retrieveObjects()
|
|
||||||
{
|
|
||||||
cout<<"Starting retrieve process..."<<endl;
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
RetrieveTypes retrieveType;
|
|
||||||
|
|
||||||
for (auto arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-rt") == 0)
|
|
||||||
{
|
|
||||||
if (value.compare("songs") == 0)
|
|
||||||
{
|
|
||||||
retrieveType = RetrieveTypes::songs;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RetrieveRecords songs{api, token};
|
|
||||||
songs.retrieve(retrieveType);
|
|
||||||
|
|
||||||
}
|
|
||||||
void CommitManager::uploadSong()
|
|
||||||
{
|
|
||||||
bool uploadSingleSong = true;
|
|
||||||
bool recursiveDirectory = false;
|
|
||||||
string songDirectory;
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
|
||||||
Song song;
|
|
||||||
|
|
||||||
for (auto& arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-s") == 0)
|
|
||||||
{
|
|
||||||
song.songPath.assign(arg.value);
|
|
||||||
}
|
|
||||||
else if (flag.compare("-sd") == 0)
|
|
||||||
{
|
|
||||||
songDirectory = value;
|
|
||||||
uploadSingleSong = false;
|
|
||||||
}
|
|
||||||
else if (flag.compare("-sr") == 0)
|
|
||||||
{
|
|
||||||
songDirectory = value;
|
|
||||||
uploadSingleSong = false;
|
|
||||||
recursiveDirectory = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Upload upld{api};
|
|
||||||
if (uploadSingleSong)
|
|
||||||
{
|
|
||||||
cout<<"Uploading song..."<<endl;
|
|
||||||
upld.uploadSong(token, song);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Uploading songs from " << songDirectory << endl;
|
|
||||||
upld.uploadSongsFromDirectory(token, songDirectory, recursiveDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
#include<iostream>
|
|
||||||
#include<fstream>
|
|
||||||
|
|
||||||
#include"Managers/FileManager.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::ifstream;
|
|
||||||
using std::ofstream;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
FileManager::FileManager() {}
|
|
||||||
FileManager::FileManager(string filePath)
|
|
||||||
{
|
|
||||||
this->filePath = filePath;
|
|
||||||
readFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FileManager::saveFile(string newFilePath)
|
|
||||||
{
|
|
||||||
if (!fileRead)
|
|
||||||
readFile();
|
|
||||||
|
|
||||||
ofstream of{newFilePath, ofstream::binary};
|
|
||||||
of.write(fileBuffer, fileBufferLength);
|
|
||||||
of.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileManager::readFile()
|
|
||||||
{
|
|
||||||
ifstream is{filePath, ifstream::binary};
|
|
||||||
if (is)
|
|
||||||
{
|
|
||||||
is.seekg (0, is.end);
|
|
||||||
fileBufferLength = is.tellg();
|
|
||||||
is.seekg (0, is.beg);
|
|
||||||
|
|
||||||
fileBuffer = new char [fileBufferLength];
|
|
||||||
|
|
||||||
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
|
||||||
is.read (fileBuffer,fileBufferLength);
|
|
||||||
|
|
||||||
if (is)
|
|
||||||
cout<<"all characters read successfully.";
|
|
||||||
else
|
|
||||||
cout<<"error: only "<<is.gcount()<<" could be read";
|
|
||||||
cout<<endl;
|
|
||||||
is.close();
|
|
||||||
fileRead = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void FileManager::modifyFilePath(string filePath)
|
|
||||||
{
|
|
||||||
this->filePath = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* FileManager::retrieveFileBuffer() const
|
|
||||||
{
|
|
||||||
return fileBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#include"Managers/TokenManager.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
|
||||||
#include<nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
using Managers::TokenManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Token;
|
|
||||||
using Models::User;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
TokenManager::TokenManager(const User& user)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
}
|
|
||||||
TokenManager::TokenManager(const User& user, API& api)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "api/" + api.version
|
|
||||||
+ "/login";
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
Token TokenManager::requestToken()
|
|
||||||
{
|
|
||||||
Token token{};
|
|
||||||
json usrObj;
|
|
||||||
|
|
||||||
usrObj["username"] = user.username;
|
|
||||||
usrObj["password"] = user.password;
|
|
||||||
|
|
||||||
cout<<"Sending request for token"<<endl;
|
|
||||||
auto url = api.url + api.endpoint;
|
|
||||||
cout<<url<<endl;
|
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
|
||||||
cpr::Body{usrObj.dump()},
|
|
||||||
cpr::Header{{"Content-Type", "application/json"}});
|
|
||||||
|
|
||||||
json res = json::parse(r.text);
|
|
||||||
token.accessToken = res["token"];
|
|
||||||
token.tokenType = res["token_type"];
|
|
||||||
|
|
||||||
cout<<"status code "<<r.status_code<<endl;
|
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#include"Managers/UserManager.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
using Models::IcarusAction;
|
|
||||||
using Models::User;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
UserManager::UserManager(User user)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
}
|
|
||||||
UserManager::UserManager(const IcarusAction icaAct)
|
|
||||||
{
|
|
||||||
this->icaAction = icaAct;
|
|
||||||
this->user = User{};
|
|
||||||
parseUserFromActions();
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
User UserManager::retrieveUser() const
|
|
||||||
{
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserManager::parseUserFromActions()
|
|
||||||
{
|
|
||||||
auto args = icaAction.flags;
|
|
||||||
|
|
||||||
for (auto arg : args)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
if (flag.compare("-u") == 0)
|
|
||||||
{
|
|
||||||
user.username = arg.value;
|
|
||||||
}
|
|
||||||
if (flag.compare("-p") == 0)
|
|
||||||
{
|
|
||||||
user.password = arg.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#include"Parsers/APIParser.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
using Models::API;
|
|
||||||
using Models::IcarusAction;
|
|
||||||
|
|
||||||
namespace Parsers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
|
||||||
{
|
|
||||||
api = API{};
|
|
||||||
parseAPI();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
API APIParser::retrieveAPI() const
|
|
||||||
{
|
|
||||||
return api;
|
|
||||||
}
|
|
||||||
|
|
||||||
void APIParser::parseAPI()
|
|
||||||
{
|
|
||||||
auto flags = icaAct.flags;
|
|
||||||
cout<<"Parsing api"<<endl;
|
|
||||||
|
|
||||||
for (auto i =0; i < flags.size(); ++i)
|
|
||||||
{
|
|
||||||
auto arg = flags[i].flag;
|
|
||||||
auto value = flags[i].value;
|
|
||||||
|
|
||||||
if (arg.compare("-h") == 0)
|
|
||||||
{
|
|
||||||
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: For now I will hard code
|
|
||||||
// the api version since I am only
|
|
||||||
// on version 1
|
|
||||||
api.version = "v1";
|
|
||||||
}
|
|
||||||
#pragma functions
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
#include"Syncers/Delete.h"
|
|
||||||
|
|
||||||
#include<exception>
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::exception;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::Token;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
Delete::Delete(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
void Delete::deleteSong(const Token token, Song song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto url = retrieveUrl(song);
|
|
||||||
string auth{token.tokenType};
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Delete(cpr::Url(url),
|
|
||||||
cpr::Header{{"authorization", auth}});
|
|
||||||
|
|
||||||
auto statusCode = r.status_code;
|
|
||||||
|
|
||||||
cout<<"Status code "<<statusCode<<endl;
|
|
||||||
}
|
|
||||||
catch (exception e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
string Delete::retrieveUrl(Song song)
|
|
||||||
{
|
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint + "/"};
|
|
||||||
|
|
||||||
url.append(std::to_string(song.id));
|
|
||||||
cout<<"url "<<url<<endl;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
#include"Syncers/Download.h"
|
|
||||||
|
|
||||||
#include<exception>
|
|
||||||
#include<iostream>
|
|
||||||
#include<fstream>
|
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::exception;
|
|
||||||
using std::ofstream;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::Token;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
#pragma
|
|
||||||
Download::Download() { }
|
|
||||||
Download::Download(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
Download::Download(string filePath)
|
|
||||||
{
|
|
||||||
downloadFilePath = filePath;
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
void Download::downloadSong(const Token token, Song song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string url = retrieveUrl(song);
|
|
||||||
song.songPath.append("track.mp3");
|
|
||||||
cout<<"song path "<<song.songPath<<endl;
|
|
||||||
string auth{token.tokenType};
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
|
|
||||||
auto r = cpr::Get(cpr::Url(url),
|
|
||||||
cpr::Header{{"Content-type", "audio/mpeg"},
|
|
||||||
{"Authorization", auth}});
|
|
||||||
|
|
||||||
|
|
||||||
int statusCode = r.status_code;
|
|
||||||
|
|
||||||
if (statusCode == OK) {
|
|
||||||
song.data = r.text;
|
|
||||||
saveSong(song);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
cout<<"finsihed with status code "<<statusCode<<endl;
|
|
||||||
}
|
|
||||||
catch (exception e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string Download::retrieveUrl(Song song)
|
|
||||||
{
|
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint + "/"};
|
|
||||||
|
|
||||||
url.append(std::to_string(song.id));
|
|
||||||
cout<<"url "<<url<<endl;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Download::saveSong(Song& song)
|
|
||||||
{
|
|
||||||
cout<<"\nSaving song to: "<<song.songPath<<endl;
|
|
||||||
int bufferLength = song.data.length();
|
|
||||||
const char *data = song.data.c_str();
|
|
||||||
cout<<"buff length "<<bufferLength<<endl;
|
|
||||||
|
|
||||||
ofstream saveSong{song.songPath, std::ios::binary};
|
|
||||||
saveSong.write(data, bufferLength);
|
|
||||||
saveSong.close();
|
|
||||||
}
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
#include "Syncers/RetrieveRecords.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <cpr/cpr.h>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include "Utilities/Conversions.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::ofstream;
|
|
||||||
|
|
||||||
using Managers::CommitManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Token;
|
|
||||||
using Utilities::Conversions;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
RetrieveRecords::RetrieveRecords() { }
|
|
||||||
RetrieveRecords::RetrieveRecords(API api, Token token)
|
|
||||||
: token(token), api(api) { }
|
|
||||||
|
|
||||||
void RetrieveRecords::retrieve(CommitManager::RetrieveTypes type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case CommitManager::RetrieveTypes::songs:
|
|
||||||
fetchSongs();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void RetrieveRecords::fetchSongs()
|
|
||||||
{
|
|
||||||
cout<<"fetching songs"<<endl;
|
|
||||||
auto url = api.url + "api/" + api.version + "/" + "song";
|
|
||||||
|
|
||||||
auto auth = token.tokenType;
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Get(cpr::Url{url},
|
|
||||||
cpr::Header{{"authorization", auth},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (r.status_code != (int)Result::OK) {
|
|
||||||
cout<<"something went wrong\n";
|
|
||||||
cout<<"status code: "<<r.status_code<<endl;
|
|
||||||
cout<<"message: "<<r.text<<endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto songData = nlohmann::json::parse(r.text);
|
|
||||||
|
|
||||||
ofstream writeData{};
|
|
||||||
writeData.open("songs.json");
|
|
||||||
writeData<<songData.dump(4);
|
|
||||||
writeData.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
#include<iostream>
|
|
||||||
#include<filesystem>
|
|
||||||
#include<exception>
|
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
|
||||||
#include<nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include"Syncers/Upload.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::exception;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
using Managers::FileManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::UploadForm;
|
|
||||||
|
|
||||||
using namespace cpr;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
Upload::Upload() { }
|
|
||||||
Upload::Upload(API api) : api(api)
|
|
||||||
{
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Song Upload::uploadSong(const Models::Token& token, Song& song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto url = retrieveUrl();
|
|
||||||
|
|
||||||
cout<<"url "<<url<<endl;
|
|
||||||
string auth{token.tokenType};
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
|
||||||
cpr::Multipart{{"key", "small value"},
|
|
||||||
{"file", cpr::File{song.songPath}}},
|
|
||||||
cpr::Header{{"authorization", auth}}
|
|
||||||
);
|
|
||||||
|
|
||||||
cout << "status code: " << r.status_code<< std::endl;
|
|
||||||
auto result = nlohmann::json::parse(r.text);
|
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
song.id = result["id"].get<int>();
|
|
||||||
song.title = result["title"].get<std::string>();
|
|
||||||
song.artist = result["artist"].get<std::string>();
|
|
||||||
song.album = result["album"].get<std::string>();
|
|
||||||
song.genre = result["genre"].get<std::string>();
|
|
||||||
song.year = result["year"].get<int>();
|
|
||||||
song.duration = result["duration"].get<int>();
|
|
||||||
song.track = result["track"].get<int>();
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
catch (exception e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Upload::uploadSongsFromDirectory(const Models::Token& token,
|
|
||||||
const std::string& directory,
|
|
||||||
bool recursive = false)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto songs = retrieveAllSongsFromDirectory(directory, recursive);
|
|
||||||
for (auto& song: songs)
|
|
||||||
{
|
|
||||||
song = uploadSong(token, song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
cout<<e.what()<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Song> Upload::retrieveAllSongsFromDirectory(const std::string& directory,
|
|
||||||
bool recursive)
|
|
||||||
{
|
|
||||||
std::vector<Song> allSongs;
|
|
||||||
if (recursive)
|
|
||||||
{
|
|
||||||
for (auto p: fs::recursive_directory_iterator(directory))
|
|
||||||
{
|
|
||||||
auto song = retrieveSongPath(p);
|
|
||||||
if (!song.songPath.empty())
|
|
||||||
allSongs.push_back(song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto p: fs::directory_iterator(directory))
|
|
||||||
{
|
|
||||||
auto song = retrieveSongPath(p);
|
|
||||||
if (!song.songPath.empty())
|
|
||||||
allSongs.push_back(song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allSongs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
string Upload::retrieveUrl()
|
|
||||||
{
|
|
||||||
const string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint};
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Song Upload::retrieveSongPath(fs::directory_entry& dirEntry)
|
|
||||||
{
|
|
||||||
constexpr auto mp3Ext = ".mp3";
|
|
||||||
Song song;
|
|
||||||
if (fs::is_regular_file(dirEntry.path()))
|
|
||||||
{
|
|
||||||
const auto ext = dirEntry.path().extension().string();
|
|
||||||
if (ext.compare(mp3Ext) == 0)
|
|
||||||
{
|
|
||||||
cout << "found mp3 file" << endl;
|
|
||||||
song.songPath = dirEntry.path().string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
void Upload::printSongDetails()
|
|
||||||
{
|
|
||||||
cout<<"Song details: "<<endl;
|
|
||||||
cout<<"Id: "<<song.id<<endl;
|
|
||||||
cout<<"Title: "<<song.title<<endl;
|
|
||||||
cout<<"Artist: "<<song.artist<<endl;
|
|
||||||
cout<<"Album: "<<song.album<<endl;
|
|
||||||
cout<<"Genre: "<<song.genre<<endl;
|
|
||||||
cout<<"Year: "<<song.year<<endl;
|
|
||||||
cout<<"Duration: "<<song.duration<<endl;
|
|
||||||
}
|
|
||||||
void Upload::printSongDetails(std::vector<Song>& songs)
|
|
||||||
{
|
|
||||||
for (auto& song: songs)
|
|
||||||
{
|
|
||||||
cout<<"Song details: "<<endl;
|
|
||||||
cout<<"Id: "<<song.id<<endl;
|
|
||||||
cout<<"Title: "<<song.title<<endl;
|
|
||||||
cout<<"Artist: "<<song.artist<<endl;
|
|
||||||
cout<<"Album: "<<song.album<<endl;
|
|
||||||
cout<<"Genre: "<<song.genre<<endl;
|
|
||||||
cout<<"Year: "<<song.year<<endl;
|
|
||||||
cout<<"Duration: "<<song.duration<<endl;
|
|
||||||
cout<<"Path: "<<song.songPath<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Upload::printJsonData(json obj)
|
|
||||||
{
|
|
||||||
cout<<endl<<endl<<"JSon data: "<<endl;
|
|
||||||
cout<<"id: "<<obj["id"]<<endl;
|
|
||||||
cout<<"title: "<<obj["title"]<<endl;
|
|
||||||
cout<<"artist: "<<obj["artist"]<<endl;
|
|
||||||
cout<<"album: "<<obj["album"]<<endl;
|
|
||||||
cout<<"genre: "<<obj["genre"]<<endl;
|
|
||||||
cout<<"year: "<<obj["year"]<<endl;
|
|
||||||
cout<<"duration: "<<obj["duration"]<<endl;
|
|
||||||
cout<<"song_data: "<<obj["song_data"]<<endl;
|
|
||||||
|
|
||||||
cout<<endl<<endl;;
|
|
||||||
}
|
|
||||||
#pragma Testing
|
|
||||||
#pragma Functions
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
#include"UI/AboutWindow.h"
|
|
||||||
|
|
||||||
using std::unique_ptr;
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
|
||||||
{
|
|
||||||
setupWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AboutWindow::setupWindow()
|
|
||||||
{
|
|
||||||
windowWidth = 250;
|
|
||||||
windowHeight = 300;
|
|
||||||
|
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
|
|
||||||
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
|
||||||
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
|
||||||
|
|
||||||
mainLayoutQt->addWidget(appName.get());
|
|
||||||
mainLayoutQt->addWidget(actionButtonQt.get());
|
|
||||||
|
|
||||||
|
|
||||||
setFixedWidth(windowWidth);
|
|
||||||
setFixedHeight(windowHeight);
|
|
||||||
|
|
||||||
setLayout(mainLayoutQt.get());
|
|
||||||
|
|
||||||
setWindowTitle("About");
|
|
||||||
|
|
||||||
connections();
|
|
||||||
}
|
|
||||||
void AboutWindow::connections()
|
|
||||||
{
|
|
||||||
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
|
||||||
SLOT(closeWindow()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AboutWindow::closeWindow()
|
|
||||||
{
|
|
||||||
this->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
#include"UI/MainWindow.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Models/UploadForm.h"
|
|
||||||
#include"Syncers/Upload.h"
|
|
||||||
#include"Utilities/Conversions.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
using std::unique_ptr;
|
|
||||||
|
|
||||||
using Models::UploadForm;
|
|
||||||
using Syncers::Upload;
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
MainWindow::MainWindow()
|
|
||||||
{
|
|
||||||
setupMainWindow();
|
|
||||||
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::configureDownloadSection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void MainWindow::configureUploadSection()
|
|
||||||
{
|
|
||||||
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
|
||||||
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
|
||||||
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
|
||||||
|
|
||||||
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
|
||||||
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
|
||||||
|
|
||||||
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
|
||||||
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
|
||||||
|
|
||||||
urlPortion.get()->addWidget(urlLabel.get());
|
|
||||||
urlPortion.get()->addWidget(urlQt.get());
|
|
||||||
|
|
||||||
songPathPortion->addWidget(songPath.get());
|
|
||||||
songPathPortion->addWidget(sourceFilePathQt.get());
|
|
||||||
|
|
||||||
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
subLayoutOneQt.get()->addLayout(urlPortion.get());
|
|
||||||
subLayoutOneQt->addLayout(songPathPortion.get());
|
|
||||||
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
|
||||||
}
|
|
||||||
void MainWindow::configureWindowDimensions()
|
|
||||||
{
|
|
||||||
windowWidth = 450;
|
|
||||||
windowHeight = 450;
|
|
||||||
}
|
|
||||||
void MainWindow::configureWindowProperties()
|
|
||||||
{
|
|
||||||
setWindowTitle("IcarusDownloadManager");
|
|
||||||
setFixedHeight(windowHeight);
|
|
||||||
setFixedWidth(windowWidth);
|
|
||||||
}
|
|
||||||
void MainWindow::connections()
|
|
||||||
{
|
|
||||||
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
|
||||||
QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this,
|
|
||||||
SLOT(exitApplication()));
|
|
||||||
QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this,
|
|
||||||
SLOT(displaySoftwareInformation()));
|
|
||||||
QObject::connect(windowComboBox.get(), SIGNAL(activated(int)),
|
|
||||||
this, SLOT(setCurrentIndex(int)));
|
|
||||||
}
|
|
||||||
void MainWindow::createMenus()
|
|
||||||
{
|
|
||||||
fileMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
|
||||||
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
|
||||||
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
|
||||||
|
|
||||||
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
|
||||||
closeApplicationQt->setText("Exit Application");
|
|
||||||
|
|
||||||
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
|
||||||
aboutApplicationQt->setText("About");
|
|
||||||
|
|
||||||
fileMenuQt->addAction(closeApplicationQt.get());
|
|
||||||
helpMenuQt->addAction(aboutApplicationQt.get());
|
|
||||||
|
|
||||||
}
|
|
||||||
void MainWindow::setupMainWidget()
|
|
||||||
{
|
|
||||||
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
|
||||||
|
|
||||||
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
|
||||||
setupWindowLists();
|
|
||||||
|
|
||||||
|
|
||||||
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
stackLayout->addWidget(windowComboBox.get());
|
|
||||||
|
|
||||||
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
|
||||||
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
|
||||||
|
|
||||||
stackLayout->addWidget(uploadSongWidgetQt.get());
|
|
||||||
|
|
||||||
mainWidgetQt->setLayout(stackLayout.get());
|
|
||||||
}
|
|
||||||
void MainWindow::setupMainWindow()
|
|
||||||
{
|
|
||||||
configureWindowDimensions();
|
|
||||||
|
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
|
||||||
|
|
||||||
configureUploadSection();
|
|
||||||
|
|
||||||
setupMainWidget();
|
|
||||||
|
|
||||||
widgetStack->addWidget(mainWidgetQt.get());
|
|
||||||
|
|
||||||
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
|
||||||
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
|
||||||
MainDockWidgetQt->setWidget(widgetStack.get());
|
|
||||||
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
|
||||||
|
|
||||||
setCentralWidget(MainDockWidgetQt.get());
|
|
||||||
|
|
||||||
createMenus();
|
|
||||||
|
|
||||||
configureWindowProperties();
|
|
||||||
|
|
||||||
connections();
|
|
||||||
}
|
|
||||||
void MainWindow::setupWindowLists()
|
|
||||||
{
|
|
||||||
windowComboBox->addItem(tr("Upload song"));
|
|
||||||
windowComboBox->addItem(tr("Download song"));
|
|
||||||
windowComboBox->addItem(tr("Display all songs"));
|
|
||||||
windowComboBox->addItem(tr("Display songs"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::exitApplication()
|
|
||||||
{
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
void MainWindow::displaySoftwareInformation()
|
|
||||||
{
|
|
||||||
aboutWindow->show();
|
|
||||||
}
|
|
||||||
void MainWindow::setCurrentIndex(int index)
|
|
||||||
{
|
|
||||||
cout<<"index "<<index<<endl;
|
|
||||||
QString qText = windowComboBox->itemText(index);
|
|
||||||
auto cnvert = Utilities::Conversions(qText);
|
|
||||||
auto convertedStr = cnvert.convertQStringToString();
|
|
||||||
cout<<"item text"<<endl;
|
|
||||||
}
|
|
||||||
void MainWindow::uploadSong()
|
|
||||||
{
|
|
||||||
uploadSongQt->setEnabled(false);
|
|
||||||
|
|
||||||
string url = urlQt->toPlainText().toUtf8().constData();
|
|
||||||
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
|
||||||
cout<<"URL endpoint: "<<url<<endl;
|
|
||||||
cout<<"Music file path: "<<filePath<<endl;
|
|
||||||
UploadForm formData{url, filePath};
|
|
||||||
|
|
||||||
Upload upld{formData};
|
|
||||||
upld.uploadSong();
|
|
||||||
|
|
||||||
uploadSongQt->setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#include"Utilities/Conversions.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::unique_ptr;
|
|
||||||
|
|
||||||
namespace Utilities
|
|
||||||
{
|
|
||||||
Conversions::Conversions()
|
|
||||||
{
|
|
||||||
initializeValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conversions::initializeValues()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
void Conversions::printValue(T val)
|
|
||||||
{
|
|
||||||
std::cout<<"going to print value"<<std::endl;
|
|
||||||
std::cout<<val<<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
pub fn print_help() {
|
||||||
|
let msg: String = String::from(
|
||||||
|
r#"icd [Action] [flag]
|
||||||
|
|
||||||
|
Actions
|
||||||
|
download
|
||||||
|
upload-meta
|
||||||
|
retrieve
|
||||||
|
delete
|
||||||
|
|
||||||
|
Flags
|
||||||
|
Required for all actions
|
||||||
|
-u username
|
||||||
|
-p password
|
||||||
|
-h api host
|
||||||
|
-ha auth api host
|
||||||
|
|
||||||
|
Required for upload with metadata
|
||||||
|
-s path of song
|
||||||
|
-t track number
|
||||||
|
-m metadata filepath
|
||||||
|
-ca coverart filepath
|
||||||
|
-scma directory where songs, metadata, and cover art exists and will be uploaded (Optional)
|
||||||
|
|
||||||
|
Required for download
|
||||||
|
-b song id
|
||||||
|
-d path to download song (Optional)
|
||||||
|
|
||||||
|
Required for retrieving records
|
||||||
|
-rt retrieve type (songs is only accepted)
|
||||||
|
|
||||||
|
Required for deleting a song
|
||||||
|
-D song id
|
||||||
|
|
||||||
|
Print version
|
||||||
|
-v"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{msg}");
|
||||||
|
}
|
||||||
+153
@@ -0,0 +1,153 @@
|
|||||||
|
mod help;
|
||||||
|
mod managers;
|
||||||
|
mod models;
|
||||||
|
mod parsers;
|
||||||
|
mod syncers;
|
||||||
|
mod utilities;
|
||||||
|
mod version;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let args_len = args.len() as i32;
|
||||||
|
|
||||||
|
if args_len == 1 {
|
||||||
|
help::print_help();
|
||||||
|
utilities::checks::exit_program(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut act_mgr = managers::action_managers::ActionManager::default();
|
||||||
|
act_mgr.set_params(&args);
|
||||||
|
act_mgr.initialize();
|
||||||
|
|
||||||
|
let chosen_act = act_mgr.retrieve_icarus_action();
|
||||||
|
for act in &chosen_act.flags {
|
||||||
|
if act.flag == "-v" {
|
||||||
|
version::print_version();
|
||||||
|
utilities::checks::exit_program(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chosen_act.print_action_and_flags();
|
||||||
|
|
||||||
|
let mut cmt_mgr = managers::commit_manager::CommitManager {
|
||||||
|
ica_action: chosen_act,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
cmt_mgr.commit_action().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::managers;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_song_prep_upload() {
|
||||||
|
let meta_path = String::from("tests/sample2_tracks/album.json");
|
||||||
|
|
||||||
|
if !std::path::Path::new(&meta_path).exists() {
|
||||||
|
assert!(false, "File does not exists: {meta_path:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
match icarus_models::album::collection::parse_album(&meta_path) {
|
||||||
|
Ok(album) => {
|
||||||
|
for track in 1..3 {
|
||||||
|
let directory_path = std::path::Path::new(&meta_path);
|
||||||
|
let directory: String = directory_path.parent().unwrap().display().to_string();
|
||||||
|
let filename: String = if track < 10 {
|
||||||
|
String::from("track0")
|
||||||
|
+ &track.to_string()
|
||||||
|
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
|
||||||
|
} else {
|
||||||
|
String::from("track")
|
||||||
|
+ &track.to_string()
|
||||||
|
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
|
||||||
|
};
|
||||||
|
let disc = 1;
|
||||||
|
match managers::commit_manager::retrieve_song(
|
||||||
|
&album, track, disc, &directory, &filename,
|
||||||
|
) {
|
||||||
|
Ok(song) => match icarus_models::song::io::to_data(&song) {
|
||||||
|
Ok(_) => {
|
||||||
|
print!("Success");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_minimum_action_and_args() {
|
||||||
|
let args: Vec<String> = vec![
|
||||||
|
"icarus-dm".to_string(),
|
||||||
|
"download".to_string(),
|
||||||
|
"-u".to_string(),
|
||||||
|
"jamborie".to_string(),
|
||||||
|
"-p".to_string(),
|
||||||
|
"somethingsecr3t!".to_string(),
|
||||||
|
"-h".to_string(),
|
||||||
|
"https://music-server.com".to_string(),
|
||||||
|
];
|
||||||
|
let arg_count = args.len() as i32;
|
||||||
|
let minimum_arg_count = 8;
|
||||||
|
assert!(arg_count >= minimum_arg_count);
|
||||||
|
|
||||||
|
let mut act_mgr = managers::action_managers::ActionManager {
|
||||||
|
action: String::new(),
|
||||||
|
flags: Vec::new(),
|
||||||
|
params: args,
|
||||||
|
param_count: arg_count,
|
||||||
|
};
|
||||||
|
act_mgr.initialize();
|
||||||
|
let ica = act_mgr.retrieve_icarus_action();
|
||||||
|
let action = &ica.action;
|
||||||
|
let flags = &ica.flags;
|
||||||
|
|
||||||
|
assert!(action != "");
|
||||||
|
assert!(flags.len() > 2);
|
||||||
|
assert!(
|
||||||
|
!(action != "download"
|
||||||
|
&& action != "upload"
|
||||||
|
&& action != "retrieve"
|
||||||
|
&& action != "upload-meta")
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut found_count = 0;
|
||||||
|
let mut flags_already_read = Vec::new();
|
||||||
|
|
||||||
|
for flag in flags {
|
||||||
|
if flags_already_read.contains(&flag.flag) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if flag.flag == "-u" {
|
||||||
|
found_count += 1;
|
||||||
|
flags_already_read.push(flag.flag.clone());
|
||||||
|
} else if flag.flag == "-p" {
|
||||||
|
found_count += 1;
|
||||||
|
flags_already_read.push(flag.flag.clone());
|
||||||
|
} else if flag.flag == "-h" {
|
||||||
|
found_count += 1;
|
||||||
|
flags_already_read.push(flag.flag.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let all_flags_found = found_count == 3;
|
||||||
|
|
||||||
|
assert_eq!(found_count, 3, "Three flags are required: -u, -p, -h");
|
||||||
|
assert!(all_flags_found, "All flags have not been found");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
use crate::{models, utilities};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ActionManager {
|
||||||
|
pub action: String,
|
||||||
|
pub flags: Vec<models::flags::Flags>,
|
||||||
|
pub params: Vec<String>,
|
||||||
|
pub param_count: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ActionManager {
|
||||||
|
fn default() -> Self {
|
||||||
|
ActionManager {
|
||||||
|
action: String::new(),
|
||||||
|
flags: Vec::new(),
|
||||||
|
params: Vec::new(),
|
||||||
|
param_count: -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActionManager {
|
||||||
|
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
|
||||||
|
models::icarus_action::IcarusAction {
|
||||||
|
flags: self.flags.clone(),
|
||||||
|
action: String::from(&self.action),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn supported_flags(&self) -> Vec<String> {
|
||||||
|
vec![
|
||||||
|
String::from("-u"),
|
||||||
|
String::from("-p"),
|
||||||
|
String::from("-t"),
|
||||||
|
String::from("-h"),
|
||||||
|
String::from("-ha"),
|
||||||
|
String::from("-s"),
|
||||||
|
String::from("-sd"),
|
||||||
|
String::from("-sr"),
|
||||||
|
String::from("-d"),
|
||||||
|
String::from("-D"),
|
||||||
|
String::from("-b"),
|
||||||
|
String::from("-rt"),
|
||||||
|
String::from("-nc"),
|
||||||
|
String::from("-m"),
|
||||||
|
String::from("-ca"),
|
||||||
|
String::from("-smca"),
|
||||||
|
String::from("-t"),
|
||||||
|
String::from("-v"),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initialize(&mut self) {
|
||||||
|
self.validate_flags();
|
||||||
|
self.validate_action();
|
||||||
|
self.action = self.action.to_lowercase();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_params(&mut self, args: &[String]) {
|
||||||
|
self.params = args.to_owned();
|
||||||
|
self.param_count = self.params.len() as i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate_flags(&mut self) {
|
||||||
|
let flag_vals = self.parsed_flags();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
while i < flag_vals.len() {
|
||||||
|
let flag = &flag_vals[i];
|
||||||
|
let mut flg = models::flags::Flags::default();
|
||||||
|
|
||||||
|
if self.is_valid_flag(flag) {
|
||||||
|
if self.does_flag_have_value(flag) {
|
||||||
|
flg.flag = String::from(flag);
|
||||||
|
flg.value = String::from(&flag_vals[i + 1]);
|
||||||
|
|
||||||
|
i += 1;
|
||||||
|
} else {
|
||||||
|
flg.flag = String::from(flag);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
utilities::checks::exit_program(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.flags.push(flg);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate_action(&mut self) {
|
||||||
|
if self.params.len() >= 2 {
|
||||||
|
let act = &self.params[1];
|
||||||
|
self.action = String::from(act);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_valid_flag(&self, flag: &String) -> bool {
|
||||||
|
let flags = self.supported_flags();
|
||||||
|
let mut found: bool = false;
|
||||||
|
|
||||||
|
for flg in &flags {
|
||||||
|
if flg == flag {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
found
|
||||||
|
}
|
||||||
|
|
||||||
|
fn does_flag_have_value(&self, flag: &String) -> bool {
|
||||||
|
let flags_tmp = self.parsed_flags();
|
||||||
|
let mut i_found: i32 = -1;
|
||||||
|
|
||||||
|
for (i, item) in flags_tmp.iter().enumerate() {
|
||||||
|
let flg = &item;
|
||||||
|
if *flg == flag {
|
||||||
|
i_found = i as i32;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i_found >= 0 {
|
||||||
|
(i_found + 1) < flags_tmp.len().try_into().unwrap()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _print_action(&self) {
|
||||||
|
if self.action.is_empty() {
|
||||||
|
println!("Action is empty");
|
||||||
|
} else {
|
||||||
|
println!("Action is {}", self.action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _print_flags(&self) {
|
||||||
|
println!("Printing flags...");
|
||||||
|
for flag in &self.flags {
|
||||||
|
println!("Flag {}", flag.flag);
|
||||||
|
println!("Value {}", flag.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parsed_flags(&self) -> Vec<String> {
|
||||||
|
let mut parsed: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
if self.param_count <= 2 {
|
||||||
|
let flag = String::from(&self.params[1]);
|
||||||
|
if flag == "-v" {
|
||||||
|
parsed.push(flag);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i in 2..self.params.len() {
|
||||||
|
let flag = String::from(&self.params[i]);
|
||||||
|
parsed.push(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parsed
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,640 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::default::Default;
|
||||||
|
use std::fs::read_dir;
|
||||||
|
use std::io::Result;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use crate::managers;
|
||||||
|
use crate::models::{self};
|
||||||
|
use crate::parsers;
|
||||||
|
use crate::syncers;
|
||||||
|
use crate::utilities;
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct CommitManager {
|
||||||
|
pub ica_action: models::icarus_action::IcarusAction,
|
||||||
|
pub api: models::api::Api,
|
||||||
|
pub auth_api: models::api::Api,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum ActionValues {
|
||||||
|
DeleteAct,
|
||||||
|
DownloadAct,
|
||||||
|
RetrieveAct,
|
||||||
|
UploadSongWithMetadata,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum En {
|
||||||
|
ImageFile,
|
||||||
|
SongFile,
|
||||||
|
MetadataFile,
|
||||||
|
Other,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct UploadSongMembers {
|
||||||
|
pub song: icarus_models::song::Song,
|
||||||
|
pub coverart: icarus_models::coverart::CoverArt,
|
||||||
|
pub token: icarus_models::token::AccessToken,
|
||||||
|
pub album: icarus_models::album::collection::Album,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn retrieve_song(
|
||||||
|
album: &icarus_models::album::collection::Album,
|
||||||
|
track: i32,
|
||||||
|
disc: i32,
|
||||||
|
directory: &str,
|
||||||
|
filename: &str,
|
||||||
|
) -> Result<icarus_models::song::Song> {
|
||||||
|
let mut found = false;
|
||||||
|
let mut song = icarus_models::song::Song::default();
|
||||||
|
|
||||||
|
for song_i in &album.tracks {
|
||||||
|
if song_i.track == track && song_i.disc == disc {
|
||||||
|
let track = song_i.clone();
|
||||||
|
song.album = album.title.clone();
|
||||||
|
song.album_artist = album.artist.clone();
|
||||||
|
song.artist = track.artist.clone();
|
||||||
|
song.audio_type = String::from(
|
||||||
|
icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION,
|
||||||
|
);
|
||||||
|
song.disc = track.disc;
|
||||||
|
song.disc_count = album.disc_count;
|
||||||
|
song.duration = track.duration as i32;
|
||||||
|
song.genre = album.genre.clone();
|
||||||
|
song.title = track.title.clone();
|
||||||
|
song.year = album.year;
|
||||||
|
song.track = track.track;
|
||||||
|
song.track_count = album.track_count;
|
||||||
|
song.directory = directory.to_owned();
|
||||||
|
song.filename = filename.to_owned();
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if found {
|
||||||
|
Ok(song)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other("Song not found"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommitManager {
|
||||||
|
pub async fn commit_action(&mut self) {
|
||||||
|
self.init_api().await;
|
||||||
|
|
||||||
|
let action = &self.ica_action.action;
|
||||||
|
println!("Committing {action} action");
|
||||||
|
|
||||||
|
let mapped_actions = &self.map_actions();
|
||||||
|
let token = self.parse_token(&self.auth_api).await;
|
||||||
|
|
||||||
|
match self.find_mapped_action(mapped_actions, action) {
|
||||||
|
ActionValues::DeleteAct => self.delete_song(&token).await,
|
||||||
|
ActionValues::DownloadAct => self.download_song(&token).await,
|
||||||
|
ActionValues::RetrieveAct => self.retrieve_object(&token).await,
|
||||||
|
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata(&token).await,
|
||||||
|
_ => {
|
||||||
|
println!("Nothing good here");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init_api(&mut self) {
|
||||||
|
let mut prsr = parsers::api_parser::APIParser {
|
||||||
|
apis: vec![models::api::Api::default(), models::api::Api::default()],
|
||||||
|
ica_act: self.ica_action.clone(),
|
||||||
|
};
|
||||||
|
prsr.parse_api(parsers::api_parser::APIType::Main);
|
||||||
|
prsr.parse_api(parsers::api_parser::APIType::Auth);
|
||||||
|
self.api = prsr.retrieve_api(parsers::api_parser::APIType::Main);
|
||||||
|
self.auth_api = prsr.retrieve_api(parsers::api_parser::APIType::Auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_mapped_action(
|
||||||
|
&self,
|
||||||
|
actions: &HashMap<String, ActionValues>,
|
||||||
|
action: &String,
|
||||||
|
) -> ActionValues {
|
||||||
|
for (key, act) in actions {
|
||||||
|
if key == action {
|
||||||
|
return act.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionValues::None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_actions(&self) -> HashMap<String, ActionValues> {
|
||||||
|
HashMap::from([
|
||||||
|
("download".to_string(), ActionValues::DownloadAct),
|
||||||
|
("download".to_string(), ActionValues::DownloadAct),
|
||||||
|
(
|
||||||
|
"upload-meta".to_string(),
|
||||||
|
ActionValues::UploadSongWithMetadata,
|
||||||
|
),
|
||||||
|
("retrieve".to_string(), ActionValues::RetrieveAct),
|
||||||
|
("delete".to_string(), ActionValues::DeleteAct),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_song(&self, token: &icarus_models::token::AccessToken) {
|
||||||
|
println!("Deleting song");
|
||||||
|
|
||||||
|
let mut del = syncers::delete::Delete {
|
||||||
|
api: self.api.clone(),
|
||||||
|
};
|
||||||
|
let mut song = icarus_models::song::Song::default();
|
||||||
|
|
||||||
|
for arg in &self.ica_action.flags {
|
||||||
|
let flag = &arg.flag;
|
||||||
|
let value = &arg.value;
|
||||||
|
|
||||||
|
if flag == "-D" {
|
||||||
|
song.id = uuid::Uuid::from_str(value.as_str()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match del.delete_song(token, &song).await {
|
||||||
|
Ok((song, _coverart)) => {
|
||||||
|
println!("Song (Id {:?}) has been successfully deleted", song.id);
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error {er:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_song(&self, token: &icarus_models::token::AccessToken) {
|
||||||
|
println!("Downloading song");
|
||||||
|
let dwn = self.ica_action.retrieve_flag_value(&String::from("-b"));
|
||||||
|
let mut dwn_loader = syncers::download::Download {
|
||||||
|
api: self.api.clone(),
|
||||||
|
};
|
||||||
|
let mut song = icarus_models::song::Song {
|
||||||
|
id: uuid::Uuid::from_str(dwn.as_str()).unwrap(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
match dwn_loader.download_song(token, &song).await {
|
||||||
|
Ok(o) => {
|
||||||
|
println!("Song downloaded");
|
||||||
|
|
||||||
|
song.data = o.as_bytes().to_vec();
|
||||||
|
song.directory = String::from(".");
|
||||||
|
song.filename = match icarus_models::song::generate_filename(
|
||||||
|
icarus_models::types::MusicType::FlacExtension,
|
||||||
|
true,
|
||||||
|
) {
|
||||||
|
Ok(filename) => filename,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error generating song filename: {err:?}");
|
||||||
|
utilities::checks::exit_program(-3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match song.save_to_filesystem() {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Song saved");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error saving song: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error {er:?}");
|
||||||
|
match er {
|
||||||
|
syncers::download::MyError::Request(error) => {
|
||||||
|
println!("Error: {error:?}");
|
||||||
|
}
|
||||||
|
syncers::download::MyError::Other(ss) => {
|
||||||
|
println!("Error: {ss:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn retrieve_object(&self, token: &icarus_models::token::AccessToken) {
|
||||||
|
println!("Retrieving song");
|
||||||
|
let rt = self.ica_action.retrieve_flag_value(&String::from("-rt"));
|
||||||
|
|
||||||
|
if rt != "songs" {
|
||||||
|
panic!("Unsupported -rt: {rt}");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut repo = syncers::retrieve_records::RetrieveRecords {
|
||||||
|
api: self.api.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match repo.get_all_songs(token).await {
|
||||||
|
Ok(o) => {
|
||||||
|
println!("Songs");
|
||||||
|
println!("=====");
|
||||||
|
for song in o {
|
||||||
|
println!("Title: {:?}", song.title);
|
||||||
|
println!("Artist: {:?}", song.artist);
|
||||||
|
println!("Album: {:?}", song.album);
|
||||||
|
println!("Year: {:?}", song.year);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error: {er:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn parse_token(&self, api: &models::api::Api) -> icarus_models::token::AccessToken {
|
||||||
|
println!("Fetching token");
|
||||||
|
|
||||||
|
let mut usr_mgr: managers::user_manager::UserManager =
|
||||||
|
managers::user_manager::UserManager {
|
||||||
|
user: icarus_models::user::User::default(),
|
||||||
|
ica_action: self.ica_action.clone(),
|
||||||
|
};
|
||||||
|
usr_mgr.parse_user_from_actions();
|
||||||
|
|
||||||
|
let usr = usr_mgr.retrieve_user();
|
||||||
|
let mut tok_mgr = managers::token_manager::TokenManager {
|
||||||
|
user: usr,
|
||||||
|
api: api.clone(),
|
||||||
|
};
|
||||||
|
tok_mgr.init();
|
||||||
|
|
||||||
|
let token = tok_mgr.request_token().await;
|
||||||
|
|
||||||
|
token.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn upload_song_with_metadata(&mut self, token: &icarus_models::token::AccessToken) {
|
||||||
|
println!("Uplodaring song with metadara");
|
||||||
|
|
||||||
|
let songpath = self.ica_action.retrieve_flag_value(&String::from("-s"));
|
||||||
|
let metadata_path = self.ica_action.retrieve_flag_value(&String::from("-m"));
|
||||||
|
let coverpath = self.ica_action.retrieve_flag_value(&String::from("-ca"));
|
||||||
|
let track_id = self.ica_action.retrieve_flag_value(&String::from("-t"));
|
||||||
|
|
||||||
|
let single_target = !songpath.is_empty()
|
||||||
|
&& !metadata_path.is_empty()
|
||||||
|
&& !coverpath.is_empty()
|
||||||
|
&& !track_id.is_empty();
|
||||||
|
|
||||||
|
let uni = self.ica_action.retrieve_flag_value(&String::from("-smca"));
|
||||||
|
let multitarget = !uni.is_empty();
|
||||||
|
|
||||||
|
if single_target && multitarget {
|
||||||
|
println!("Cannot upload from source and directory");
|
||||||
|
panic!("What??");
|
||||||
|
}
|
||||||
|
|
||||||
|
if single_target {
|
||||||
|
println!("Song path: {songpath}");
|
||||||
|
println!("Track ID: {track_id}");
|
||||||
|
println!("metadata path: {metadata_path}");
|
||||||
|
println!("cover art path: {coverpath}");
|
||||||
|
|
||||||
|
let _ = self
|
||||||
|
.sing_target_upload(&songpath, &track_id, &metadata_path, &coverpath, token)
|
||||||
|
.await;
|
||||||
|
} else if multitarget {
|
||||||
|
let _ = self.multi_target_upload(&uni, token).await;
|
||||||
|
} else {
|
||||||
|
eprintln!("Single or Multi target has not been chosen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Only uploading one song
|
||||||
|
async fn sing_target_upload(
|
||||||
|
&mut self,
|
||||||
|
songpath: &String,
|
||||||
|
track_id: &str,
|
||||||
|
meta_path: &String,
|
||||||
|
cover_path: &str,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
) -> Result<()> {
|
||||||
|
let song_file = std::path::Path::new(&songpath);
|
||||||
|
|
||||||
|
if !song_file.exists() {
|
||||||
|
println!("Song file does not exist");
|
||||||
|
panic!("Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
let pa = std::path::Path::new(&cover_path);
|
||||||
|
|
||||||
|
let mut cover_art = icarus_models::coverart::CoverArt {
|
||||||
|
directory: String::from(pa.parent().unwrap().to_str().unwrap()),
|
||||||
|
filename: String::from(pa.file_name().unwrap().to_str().unwrap()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let file_name = std::ffi::OsString::from(&song_file.file_name().unwrap());
|
||||||
|
|
||||||
|
match self.find_file_extension(&file_name) {
|
||||||
|
En::SongFile => match utilities::string::o_to_string(&file_name) {
|
||||||
|
Ok(s) => {
|
||||||
|
println!("file name: {file_name:?}");
|
||||||
|
|
||||||
|
match icarus_models::album::collection::parse_album(meta_path) {
|
||||||
|
Ok(album) => {
|
||||||
|
let filename = s.clone();
|
||||||
|
let directory = song_file.parent().unwrap().display().to_string();
|
||||||
|
let trck = i32::from_str(track_id).unwrap();
|
||||||
|
let mut s =
|
||||||
|
retrieve_song(&album, trck, 1, &directory, &filename).unwrap();
|
||||||
|
println!("Directory: {:?}", s.directory);
|
||||||
|
println!("Filename: {:?}", s.filename);
|
||||||
|
println!("Path: {:?}", s.song_path());
|
||||||
|
s.data = icarus_models::song::io::to_data(&s).unwrap();
|
||||||
|
cover_art.data =
|
||||||
|
icarus_models::coverart::io::to_data(&cover_art).unwrap();
|
||||||
|
|
||||||
|
let members = UploadSongMembers {
|
||||||
|
song: s,
|
||||||
|
coverart: cover_art,
|
||||||
|
token: token.clone(),
|
||||||
|
album,
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.upload_song_process(&members).await {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("Error: {err:?}");
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error: {er:?}");
|
||||||
|
Err(std::io::Error::other(er.to_string()))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => Err(std::io::Error::other("No sutitable file found".to_owned())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Upload song to the queue to get processed
|
||||||
|
async fn upload_song_process(&self, data: &UploadSongMembers) -> Result<()> {
|
||||||
|
let mut up = syncers::upload::Upload::default();
|
||||||
|
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
||||||
|
up.set_api(&host);
|
||||||
|
|
||||||
|
let token = &data.token;
|
||||||
|
let song = &data.song;
|
||||||
|
let album = &data.album;
|
||||||
|
let coverart = &data.coverart;
|
||||||
|
|
||||||
|
println!("Queueing song");
|
||||||
|
|
||||||
|
let queued_song_id = match up.queue_song(token, song).await {
|
||||||
|
Ok(id) => id,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(std::io::Error::other(err.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Queued song Id: {queued_song_id:?}");
|
||||||
|
|
||||||
|
match up.link_user_to_queued_song(token, &queued_song_id).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Queued song linked to user");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(std::io::Error::other(err.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let queued_metadata_id = match up.queue_metadata(token, album, song, &queued_song_id).await
|
||||||
|
{
|
||||||
|
Ok(id) => id,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(std::io::Error::other(err.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Queued metadata Id: {queued_metadata_id:?}");
|
||||||
|
|
||||||
|
match up.queue_coverart(token, coverart).await {
|
||||||
|
Ok(id) => match up
|
||||||
|
.link_queued_song_to_queued_coverart(token, &queued_song_id, &id)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => match up
|
||||||
|
.update_queued_song_status(token, &queued_song_id, "ready")
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Queued coverart Id: {id:?}");
|
||||||
|
println!("Linked queued song to queued coverart");
|
||||||
|
println!("Queued status updated");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_songs(
|
||||||
|
&self,
|
||||||
|
metadata_path: &String,
|
||||||
|
source_directory: &str,
|
||||||
|
) -> Result<Vec<icarus_models::song::Song>> {
|
||||||
|
match icarus_models::album::collection::parse_album(metadata_path) {
|
||||||
|
Ok(albums) => {
|
||||||
|
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
|
||||||
|
|
||||||
|
for track in &albums.tracks {
|
||||||
|
let song_filename = if track.track < 10 {
|
||||||
|
"track0".to_owned()
|
||||||
|
+ &track.track.to_string()
|
||||||
|
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
|
||||||
|
} else {
|
||||||
|
"track".to_owned()
|
||||||
|
+ &track.track.to_string()
|
||||||
|
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
|
||||||
|
};
|
||||||
|
|
||||||
|
songs.push(icarus_models::song::Song {
|
||||||
|
title: track.title.clone(),
|
||||||
|
artist: track.artist.clone(),
|
||||||
|
disc: track.disc,
|
||||||
|
track: track.track,
|
||||||
|
duration: track.duration as i32,
|
||||||
|
year: albums.year,
|
||||||
|
album_artist: albums.artist.clone(),
|
||||||
|
genre: albums.genre.clone(),
|
||||||
|
disc_count: albums.disc_count,
|
||||||
|
track_count: albums.track_count,
|
||||||
|
album: albums.title.clone(),
|
||||||
|
audio_type: String::from("FLAC"),
|
||||||
|
directory: source_directory.to_owned(),
|
||||||
|
filename: song_filename,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(songs)
|
||||||
|
}
|
||||||
|
Err(_) => Err(std::io::Error::other("Songs not retrieved")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn multi_target_upload(
|
||||||
|
&mut self,
|
||||||
|
sourcepath: &String,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
) -> std::io::Result<()> {
|
||||||
|
let directory_path = std::path::Path::new(&sourcepath);
|
||||||
|
|
||||||
|
if !directory_path.exists() {
|
||||||
|
panic!("Directory does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
let (coverart_directory, coverart_filename) =
|
||||||
|
self.get_coverart_dir_and_filename(sourcepath).unwrap();
|
||||||
|
let mut cover_art = icarus_models::coverart::init::init_coverart_dir_and_filename(
|
||||||
|
&coverart_directory,
|
||||||
|
&coverart_filename,
|
||||||
|
);
|
||||||
|
let metadatapath = self.get_metadata_path(sourcepath).unwrap_or_default();
|
||||||
|
|
||||||
|
let mut up = syncers::upload::Upload::default();
|
||||||
|
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
||||||
|
up.set_api(&host);
|
||||||
|
|
||||||
|
cover_art.data = icarus_models::coverart::io::to_data(&cover_art).unwrap();
|
||||||
|
|
||||||
|
match self.get_songs(&metadatapath, sourcepath) {
|
||||||
|
Ok(sngs) => match icarus_models::album::collection::parse_album(&metadatapath) {
|
||||||
|
Ok(album) => {
|
||||||
|
for song in sngs {
|
||||||
|
let members = UploadSongMembers {
|
||||||
|
song,
|
||||||
|
coverart: cover_art.clone(),
|
||||||
|
token: token.clone(),
|
||||||
|
album: album.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.upload_song_process(&members).await {
|
||||||
|
Ok(o) => {
|
||||||
|
println!("Response: {o:?}");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(error) => {
|
||||||
|
eprintln!("Error: {error:?}");
|
||||||
|
Err(std::io::Error::other(error.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_coverart_dir_and_filename(&self, directory: &str) -> Result<(String, String)> {
|
||||||
|
for entry in read_dir(std::path::Path::new(directory))? {
|
||||||
|
let entry = entry?;
|
||||||
|
|
||||||
|
let file_type = entry.file_type();
|
||||||
|
let file_name = entry.file_name();
|
||||||
|
|
||||||
|
println!("file type: {file_type:?}");
|
||||||
|
println!("file name: {file_name:?}");
|
||||||
|
|
||||||
|
if let En::ImageFile = self.find_file_extension(&file_name) {
|
||||||
|
let fname = utilities::string::o_to_string(&file_name);
|
||||||
|
return Ok((directory.to_string(), fname.unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(std::io::Error::other(
|
||||||
|
"CoverArt directory and filename not found",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_file_extension(&self, file_name: &std::ffi::OsString) -> En {
|
||||||
|
let file_name_str = Some(file_name.clone().into_string());
|
||||||
|
|
||||||
|
match file_name_str {
|
||||||
|
Some(string) => {
|
||||||
|
let a = string.unwrap();
|
||||||
|
let split = a.split(".");
|
||||||
|
let mut last_index = 0;
|
||||||
|
|
||||||
|
for _ in split.clone() {
|
||||||
|
last_index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut extension = String::new();
|
||||||
|
let mut index = 1;
|
||||||
|
|
||||||
|
for word in split {
|
||||||
|
if index == last_index {
|
||||||
|
extension = word.to_string();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if extension == icarus_models::constants::file_extensions::audio::WAVEXTENSION[1..]
|
||||||
|
|| extension
|
||||||
|
== icarus_models::constants::file_extensions::audio::FLACEXTENSION[1..]
|
||||||
|
{
|
||||||
|
return En::SongFile;
|
||||||
|
} else if extension == "json" {
|
||||||
|
return En::MetadataFile;
|
||||||
|
} else if extension
|
||||||
|
== icarus_models::constants::file_extensions::image::JPGEXTENSION[1..]
|
||||||
|
|| extension == "jpeg"
|
||||||
|
|| extension == "png"
|
||||||
|
{
|
||||||
|
return En::ImageFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return En::Other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
En::Other
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_metadata_path(&self, directory_path: &String) -> Result<String> {
|
||||||
|
for entry in read_dir(std::path::Path::new(directory_path))? {
|
||||||
|
let entry = entry?;
|
||||||
|
|
||||||
|
let file_type = entry.file_type();
|
||||||
|
let file_name = entry.file_name();
|
||||||
|
|
||||||
|
println!("file type: {file_type:?}");
|
||||||
|
println!("file name: {file_name:?}");
|
||||||
|
|
||||||
|
if let En::MetadataFile = self.find_file_extension(&file_name) {
|
||||||
|
let directory_part = directory_path.clone();
|
||||||
|
let fname = utilities::string::o_to_string(&file_name);
|
||||||
|
return Ok(format!("{}/{}", directory_part, &fname.unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(std::io::Error::other("Metadata path not found"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod action_managers;
|
||||||
|
pub mod commit_manager;
|
||||||
|
pub mod token_manager;
|
||||||
|
pub mod user_manager;
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
mod response {
|
||||||
|
pub mod token {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TokenManager {
|
||||||
|
pub user: icarus_models::user::User,
|
||||||
|
pub api: models::api::Api,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for TokenManager {
|
||||||
|
fn default() -> Self {
|
||||||
|
let mut token = TokenManager {
|
||||||
|
user: icarus_models::user::User::default(),
|
||||||
|
api: models::api::Api::default(),
|
||||||
|
};
|
||||||
|
token.init();
|
||||||
|
|
||||||
|
token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TokenManager {
|
||||||
|
pub async fn request_token(&self) -> Result<icarus_models::token::AccessToken, std::io::Error> {
|
||||||
|
println!("Sending request for a token");
|
||||||
|
|
||||||
|
let url = self.retrieve_url();
|
||||||
|
println!("URL: {url}");
|
||||||
|
|
||||||
|
let mut token = icarus_models::token::AccessToken {
|
||||||
|
user_id: uuid::Uuid::nil(),
|
||||||
|
username: String::new(),
|
||||||
|
token: String::new(),
|
||||||
|
token_type: String::new(),
|
||||||
|
expiration: -1,
|
||||||
|
message: String::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let response = client.post(&url).json(&self.user).send().await.unwrap();
|
||||||
|
|
||||||
|
match response.status() {
|
||||||
|
reqwest::StatusCode::OK => {
|
||||||
|
// on success, parse our JSON to an APIResponse
|
||||||
|
match response.json::<response::token::Response>().await {
|
||||||
|
Ok(response) => {
|
||||||
|
let login_result = &response.data[0];
|
||||||
|
token.user_id = login_result.id;
|
||||||
|
token.username = login_result.username.clone();
|
||||||
|
token.token = login_result.token.clone();
|
||||||
|
token.token_type = login_result.token_type.clone();
|
||||||
|
token.expiration = login_result.expiration;
|
||||||
|
token.message = response.message;
|
||||||
|
Ok(token)
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
|
Err(std::io::Error::other("Need to grab a new token"))
|
||||||
|
}
|
||||||
|
other => {
|
||||||
|
panic!("Uh oh! Something unexpected happened: {other:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&mut self) {
|
||||||
|
let api = &mut self.api;
|
||||||
|
api.version = String::from(crate::parsers::api_parser::API_VERSION);
|
||||||
|
api.endpoint = format!("api/{}/login", api.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn retrieve_url(&self) -> String {
|
||||||
|
format!("{}{}", self.api.url, self.api.endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use crate::models::{self};
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct UserManager {
|
||||||
|
pub user: icarus_models::user::User,
|
||||||
|
pub ica_action: models::icarus_action::IcarusAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserManager {
|
||||||
|
pub fn retrieve_user(&self) -> icarus_models::user::User {
|
||||||
|
self.user.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_user_from_actions(&mut self) {
|
||||||
|
let args = &self.ica_action.flags;
|
||||||
|
|
||||||
|
// Quit the loop when two are found
|
||||||
|
let mut amt: i32 = 0;
|
||||||
|
for arg in args {
|
||||||
|
let flag = &arg.flag;
|
||||||
|
|
||||||
|
if flag == "-u" {
|
||||||
|
self.user.username = String::from(&arg.value);
|
||||||
|
amt += 1;
|
||||||
|
} else if flag == "-p" {
|
||||||
|
self.user.password = String::from(&arg.value);
|
||||||
|
amt += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if amt == 2 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct Api {
|
||||||
|
pub url: String,
|
||||||
|
pub endpoint: String,
|
||||||
|
pub version: String,
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct Flags {
|
||||||
|
pub flag: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct IcarusAction {
|
||||||
|
pub action: String,
|
||||||
|
pub flags: Vec<models::flags::Flags>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IcarusAction {
|
||||||
|
pub fn retrieve_flag_value(&self, flag: &String) -> String {
|
||||||
|
let mut val: String = String::new();
|
||||||
|
|
||||||
|
for f in self.flags.iter() {
|
||||||
|
if f.flag == *flag {
|
||||||
|
val = f.value.clone();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_action_and_flags(&self) {
|
||||||
|
println!("Action: {}", self.action);
|
||||||
|
println!("Flag count: {}", self.flags.len());
|
||||||
|
|
||||||
|
for flag in self.flags.iter() {
|
||||||
|
println!("flag {} value {}", flag.flag, flag.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod api;
|
||||||
|
pub mod flags;
|
||||||
|
pub mod icarus_action;
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
use crate::models;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct APIParser {
|
||||||
|
pub apis: Vec<models::api::Api>,
|
||||||
|
pub ica_act: models::icarus_action::IcarusAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const API_VERSION: &str = "v2";
|
||||||
|
|
||||||
|
pub enum APIType {
|
||||||
|
Main,
|
||||||
|
Auth,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl APIParser {
|
||||||
|
pub fn retrieve_api(&self, api_type: APIType) -> models::api::Api {
|
||||||
|
match api_type {
|
||||||
|
APIType::Main => self.apis[0].clone(),
|
||||||
|
APIType::Auth => self.apis[1].clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_api(&mut self, api_type: APIType) {
|
||||||
|
let flags = self.ica_act.flags.clone();
|
||||||
|
println!("Parsing api");
|
||||||
|
|
||||||
|
for elem in flags {
|
||||||
|
let arg = elem.flag;
|
||||||
|
let value = elem.value;
|
||||||
|
|
||||||
|
match api_type {
|
||||||
|
APIType::Main => {
|
||||||
|
if arg == "-h" {
|
||||||
|
if value.chars().nth(value.len() - 1) == Some('/') {
|
||||||
|
self.apis[0].url = value;
|
||||||
|
} else {
|
||||||
|
self.apis[0].url = format!("{value}/");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
APIType::Auth => {
|
||||||
|
if arg == "-ha" {
|
||||||
|
if value.chars().nth(value.len() - 1) == Some('/') {
|
||||||
|
self.apis[1].url = value;
|
||||||
|
} else {
|
||||||
|
self.apis[1].url = format!("{value}/");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for api in &mut self.apis {
|
||||||
|
api.version = String::from(API_VERSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod api_parser;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
use crate::models;
|
||||||
|
|
||||||
|
pub fn retrieve_url(api: &models::api::Api, with_id: bool, id: &uuid::Uuid) -> String {
|
||||||
|
if with_id {
|
||||||
|
retrieve_url_with_id(api, id)
|
||||||
|
} else {
|
||||||
|
retrieve_url_reg(api)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn retrieve_url_reg(api: &models::api::Api) -> String {
|
||||||
|
format!("{}api/{}/{}/", api.url, api.version, api.endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn retrieve_url_with_id(api: &models::api::Api, id: &uuid::Uuid) -> String {
|
||||||
|
format!("{}api/{}/{}/{}", api.url, api.version, api.endpoint, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn auth_header(
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
) -> Result<(http::HeaderName, http::HeaderValue), http::header::InvalidHeaderValue> {
|
||||||
|
match http::HeaderValue::from_str(&token.bearer_token()) {
|
||||||
|
Ok(auth_value) => Ok((reqwest::header::AUTHORIZATION, auth_value)),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use reqwest;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct Delete {
|
||||||
|
pub api: models::api::Api,
|
||||||
|
}
|
||||||
|
|
||||||
|
mod response {
|
||||||
|
pub mod delete_song {
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct SongAndCoverArt {
|
||||||
|
pub song: icarus_models::song::Song,
|
||||||
|
pub coverart: icarus_models::coverart::CoverArt,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<SongAndCoverArt>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Delete {
|
||||||
|
pub async fn delete_song(
|
||||||
|
&mut self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
song: &icarus_models::song::Song,
|
||||||
|
) -> Result<(icarus_models::song::Song, icarus_models::coverart::CoverArt), std::io::Error>
|
||||||
|
{
|
||||||
|
self.api.endpoint = "api/v2/song".to_owned();
|
||||||
|
let url = format!("{}{}/{}", self.api.url, self.api.endpoint, song.id);
|
||||||
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
let access_token = token.bearer_token();
|
||||||
|
let response = client
|
||||||
|
.delete(&url)
|
||||||
|
.header(reqwest::header::AUTHORIZATION, access_token)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
match response.status() {
|
||||||
|
reqwest::StatusCode::OK => {
|
||||||
|
println!("Success!");
|
||||||
|
|
||||||
|
match response.json::<response::delete_song::Response>().await {
|
||||||
|
Ok(resp) => {
|
||||||
|
println!("Response message: {:?}", resp.message);
|
||||||
|
let data = &resp.data[0];
|
||||||
|
Ok((data.song.clone(), data.coverart.clone()))
|
||||||
|
}
|
||||||
|
Err(er) => Err(std::io::Error::other(er.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
other => Err(std::io::Error::other(other.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
use crate::syncers;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Download {
|
||||||
|
pub api: models::api::Api,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MyError {
|
||||||
|
Request(reqwest::Error),
|
||||||
|
Other(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Download {
|
||||||
|
pub async fn download_song(
|
||||||
|
&mut self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
song: &icarus_models::song::Song,
|
||||||
|
) -> Result<String, MyError> {
|
||||||
|
self.api.endpoint = String::from("song/download");
|
||||||
|
let url = syncers::common::retrieve_url(&self.api, true, &song.id);
|
||||||
|
let access_token = token.bearer_token();
|
||||||
|
|
||||||
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
|
||||||
|
match client
|
||||||
|
.get(&url)
|
||||||
|
.header(reqwest::header::AUTHORIZATION, &access_token)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(rep) => match rep.status() {
|
||||||
|
reqwest::StatusCode::OK => match rep.text().await {
|
||||||
|
Ok(e) => Ok(e),
|
||||||
|
Err(er) => Err(MyError::Other(er.to_string())),
|
||||||
|
},
|
||||||
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
|
Err(MyError::Other(String::from("Need to grab a new token")))
|
||||||
|
}
|
||||||
|
other => Err(MyError::Other(other.to_string())),
|
||||||
|
},
|
||||||
|
Err(er) => Err(MyError::Request(er)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod common;
|
||||||
|
pub mod delete;
|
||||||
|
pub mod download;
|
||||||
|
pub mod retrieve_records;
|
||||||
|
pub mod upload;
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
use std::io::Error;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct RetrieveRecords {
|
||||||
|
pub api: models::api::Api,
|
||||||
|
}
|
||||||
|
|
||||||
|
mod response {
|
||||||
|
pub mod get_all_songs {
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<icarus_models::song::Song>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RetrieveRecords {
|
||||||
|
pub async fn get_all_songs(
|
||||||
|
&mut self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
) -> Result<Vec<icarus_models::song::Song>, Error> {
|
||||||
|
self.api.endpoint = String::from("api/v2/song/all");
|
||||||
|
let url = format!("{}{}", self.api.url, self.api.endpoint);
|
||||||
|
let access_token = token.bearer_token();
|
||||||
|
|
||||||
|
println!("url: {url:?}");
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
let response = client
|
||||||
|
.get(&url)
|
||||||
|
.header(reqwest::header::AUTHORIZATION, access_token)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
match response.status() {
|
||||||
|
reqwest::StatusCode::OK => {
|
||||||
|
// on success, parse our JSON to an API Response
|
||||||
|
match response.json::<response::get_all_songs::Response>().await {
|
||||||
|
Ok(parsed) => {
|
||||||
|
println!("Response message: {:?}", parsed.message);
|
||||||
|
Ok(parsed.data)
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
|
Err(std::io::Error::other("Need to grab a new token"))
|
||||||
|
}
|
||||||
|
other => Err(std::io::Error::other(other.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,304 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use http::HeaderValue;
|
||||||
|
use reqwest;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
use crate::syncers;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Upload {
|
||||||
|
pub api: models::api::Api,
|
||||||
|
}
|
||||||
|
|
||||||
|
mod response {
|
||||||
|
pub mod queue_song {
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod queue_metadata {
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod queue_coverart {
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Upload {
|
||||||
|
pub async fn queue_song(
|
||||||
|
&self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
song: &icarus_models::song::Song,
|
||||||
|
) -> Result<uuid::Uuid, reqwest::Error> {
|
||||||
|
let songpath = song.song_path().unwrap();
|
||||||
|
let file = tokio::fs::File::open(&songpath).await.unwrap();
|
||||||
|
let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new());
|
||||||
|
let file_body = reqwest::Body::wrap_stream(stream);
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new().part(
|
||||||
|
"file",
|
||||||
|
reqwest::multipart::Part::stream(file_body)
|
||||||
|
.file_name(song.filename.clone())
|
||||||
|
.mime_str("application/octet-stream")
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let endpoint = String::from("api/v2/song/queue");
|
||||||
|
let url = format!("{}/{endpoint}", self.api.url);
|
||||||
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
let (auth, auth_val) = syncers::common::auth_header(token).await.unwrap();
|
||||||
|
headers.insert(auth, auth_val);
|
||||||
|
headers.insert("Accept", HeaderValue::from_str("*/*").unwrap());
|
||||||
|
headers.insert("Connection", HeaderValue::from_str("keep-alive").unwrap());
|
||||||
|
headers.insert("Cache-Control", HeaderValue::from_str("no-cache").unwrap());
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(std::time::Duration::from_secs(300))
|
||||||
|
.pool_idle_timeout(std::time::Duration::from_secs(30))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
match client
|
||||||
|
.post(url)
|
||||||
|
.headers(headers)
|
||||||
|
.multipart(form)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => match response.json::<response::queue_song::Response>().await {
|
||||||
|
Ok(resp) => {
|
||||||
|
println!("Message: {:?}", resp.message);
|
||||||
|
Ok(resp.data[0])
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn link_user_to_queued_song(
|
||||||
|
&self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
queued_song_id: &uuid::Uuid,
|
||||||
|
) -> Result<(), reqwest::Error> {
|
||||||
|
let endpoint = String::from("api/v2/song/queue/link");
|
||||||
|
let url = format!("{}/{endpoint}", self.api.url);
|
||||||
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
let (auth, auth_val) = syncers::common::auth_header(token).await.unwrap();
|
||||||
|
headers.insert(auth, auth_val);
|
||||||
|
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"song_queue_id": queued_song_id,
|
||||||
|
"user_id": token.user_id
|
||||||
|
});
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
|
||||||
|
match client
|
||||||
|
.patch(url)
|
||||||
|
.headers(headers)
|
||||||
|
.json(&payload)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn queue_metadata(
|
||||||
|
&self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
album: &icarus_models::album::collection::Album,
|
||||||
|
song: &icarus_models::song::Song,
|
||||||
|
queued_song_id: &uuid::Uuid,
|
||||||
|
) -> Result<uuid::Uuid, reqwest::Error> {
|
||||||
|
let endpoint = String::from("api/v2/song/metadata/queue");
|
||||||
|
let url = format!("{}/{endpoint}", self.api.url);
|
||||||
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
let (auth, auth_val) = syncers::common::auth_header(token).await.unwrap();
|
||||||
|
headers.insert(auth, auth_val);
|
||||||
|
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"song_queue_id": queued_song_id,
|
||||||
|
"title": song.title,
|
||||||
|
"artist": song.artist,
|
||||||
|
"album_artist": album.artist,
|
||||||
|
"album": album.title,
|
||||||
|
"genre": song.genre,
|
||||||
|
"track": song.track,
|
||||||
|
"track_count": album.track_count,
|
||||||
|
"disc": song.disc,
|
||||||
|
"disc_count": album.disc_count,
|
||||||
|
"year": album.year,
|
||||||
|
"duration": song.duration,
|
||||||
|
});
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
|
||||||
|
match client
|
||||||
|
.post(url)
|
||||||
|
.headers(headers)
|
||||||
|
.json(&payload)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => match response.json::<response::queue_metadata::Response>().await {
|
||||||
|
Ok(resp) => {
|
||||||
|
println!("Message: {:?}", resp.message);
|
||||||
|
|
||||||
|
Ok(resp.data[0])
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn queue_coverart(
|
||||||
|
&self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
coverart: &icarus_models::coverart::CoverArt,
|
||||||
|
) -> Result<uuid::Uuid, reqwest::Error> {
|
||||||
|
let coverartpath = coverart.get_path().unwrap();
|
||||||
|
let file = tokio::fs::File::open(&coverartpath).await.unwrap();
|
||||||
|
let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new());
|
||||||
|
let file_body = reqwest::Body::wrap_stream(stream);
|
||||||
|
|
||||||
|
let file_name = std::path::Path::new(&coverartpath)
|
||||||
|
.file_name()
|
||||||
|
.and_then(|name| name.to_str())
|
||||||
|
.map(String::from)
|
||||||
|
.unwrap_or("file".to_string());
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new().part(
|
||||||
|
"file",
|
||||||
|
reqwest::multipart::Part::stream(file_body)
|
||||||
|
.file_name(file_name)
|
||||||
|
.mime_str("application/octet-stream")
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let endpoint = String::from("api/v2/coverart/queue");
|
||||||
|
let url = format!("{}/{endpoint}", self.api.url);
|
||||||
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
let (auth, auth_val) = syncers::common::auth_header(token).await.unwrap();
|
||||||
|
headers.insert(auth, auth_val);
|
||||||
|
headers.insert("Accept", HeaderValue::from_str("*/*").unwrap());
|
||||||
|
headers.insert("Connection", HeaderValue::from_str("keep-alive").unwrap());
|
||||||
|
headers.insert("Cache-Control", HeaderValue::from_str("no-cache").unwrap());
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(std::time::Duration::from_secs(300))
|
||||||
|
.pool_idle_timeout(std::time::Duration::from_secs(30))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
match client
|
||||||
|
.post(url)
|
||||||
|
.headers(headers)
|
||||||
|
.multipart(form)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => match response.json::<response::queue_coverart::Response>().await {
|
||||||
|
Ok(resp) => {
|
||||||
|
println!("Message: {:?}", resp.message);
|
||||||
|
Ok(resp.data[0])
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn link_queued_song_to_queued_coverart(
|
||||||
|
&self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
queued_song_id: &uuid::Uuid,
|
||||||
|
queued_coverart_id: &uuid::Uuid,
|
||||||
|
) -> Result<(), reqwest::Error> {
|
||||||
|
let endpoint = String::from("api/v2/coverart/queue/link");
|
||||||
|
let url = format!("{}/{endpoint}", self.api.url);
|
||||||
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
let (auth, auth_val) = syncers::common::auth_header(token).await.unwrap();
|
||||||
|
headers.insert(auth, auth_val);
|
||||||
|
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"song_queue_id": queued_song_id,
|
||||||
|
"coverart_id": queued_coverart_id
|
||||||
|
});
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
|
||||||
|
match client
|
||||||
|
.patch(url)
|
||||||
|
.headers(headers)
|
||||||
|
.json(&payload)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_queued_song_status(
|
||||||
|
&self,
|
||||||
|
token: &icarus_models::token::AccessToken,
|
||||||
|
queued_song_id: &uuid::Uuid,
|
||||||
|
status: &str,
|
||||||
|
) -> Result<(), reqwest::Error> {
|
||||||
|
let endpoint = String::from("api/v2/song/queue");
|
||||||
|
let url = format!("{}/{endpoint}", self.api.url);
|
||||||
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
let (auth, auth_val) = syncers::common::auth_header(token).await.unwrap();
|
||||||
|
headers.insert(auth, auth_val);
|
||||||
|
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"id": queued_song_id,
|
||||||
|
"status": status
|
||||||
|
});
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
|
||||||
|
match client
|
||||||
|
.patch(url)
|
||||||
|
.headers(headers)
|
||||||
|
.json(&payload)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_api(&mut self, host: &str) {
|
||||||
|
let api = models::api::Api {
|
||||||
|
url: host.to_owned(),
|
||||||
|
version: String::from(crate::parsers::api_parser::API_VERSION),
|
||||||
|
endpoint: String::new(),
|
||||||
|
};
|
||||||
|
self.api = api;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
pub fn exit_program(code: i32) {
|
||||||
|
std::process::exit(code);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod checks;
|
||||||
|
pub mod string;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
pub fn o_to_string(val: &std::ffi::OsString) -> Result<std::string::String, std::io::Error> {
|
||||||
|
match val.clone().into_string() {
|
||||||
|
Ok(value) => Ok(value),
|
||||||
|
Err(err) => match err.into_string() {
|
||||||
|
Ok(res) => Err(std::io::Error::other(res.to_string())),
|
||||||
|
Err(err) => match err.to_str() {
|
||||||
|
Some(err) => Err(std::io::Error::other(err)),
|
||||||
|
None => Err(std::io::Error::other("Undefined error")),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
pub fn print_version() {
|
||||||
|
let name = env!("CARGO_PKG_NAME");
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
println!("{name:?} {version:?}");
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"album": "Sample Tracks 2",
|
||||||
|
"album_artist": "KD",
|
||||||
|
"genre": "Country",
|
||||||
|
"year": 2025,
|
||||||
|
"track_count": 3,
|
||||||
|
"disc_count": 1,
|
||||||
|
"tracks": [
|
||||||
|
{
|
||||||
|
"title": "Uh huh",
|
||||||
|
"artist": "KD",
|
||||||
|
"disc": 1,
|
||||||
|
"track": 1,
|
||||||
|
"duration": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Bold and brash",
|
||||||
|
"artist": "KD",
|
||||||
|
"disc": 1,
|
||||||
|
"track": 2,
|
||||||
|
"duration": 37
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "How does this work?",
|
||||||
|
"artist": "KD",
|
||||||
|
"disc": 1,
|
||||||
|
"track": 3,
|
||||||
|
"duration": 46
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user