Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
B
Backend Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SpinShare
Backend Server
Commits
eed43378
Commit
eed43378
authored
Jul 01, 2021
by
SpinShare
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added mp3 support to api
parent
7f8bd609
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
src/Controller/API/APISongController.php
src/Controller/API/APISongController.php
+19
-1
No files found.
src/Controller/API/APISongController.php
View file @
eed43378
...
...
@@ -45,8 +45,19 @@ class APISongController extends AbstractController
$em
->
persist
(
$result
);
$em
->
flush
();
// TODO: This is a quick fix for mp3 support, swap with proper mp3 flag later on
$oggURL
=
$baseUrl
.
"/uploads/audio/"
.
$result
->
getFileReference
()
.
"_0.ogg"
;
$mp3URL
=
$baseUrl
.
"/uploads/audio/"
.
$result
->
getFileReference
()
.
"_0.mp3"
;
$oggHeaders
=
get_headers
(
$oggURL
);
if
(
stripos
(
$oggHeaders
[
0
],
"200 OK"
))
{
$audioURL
=
$oggURL
;
}
else
{
$audioURL
=
$mp3URL
;
}
$data
=
$result
->
getJSON
();
$data
[
'paths'
][
'ogg'
]
=
$
baseUrl
.
"/uploads/audio/"
.
$result
->
getFileReference
()
.
"_0.ogg"
;
$data
[
'paths'
][
'ogg'
]
=
$
audioURL
;
$data
[
'paths'
][
'cover'
]
=
$baseUrl
.
"/uploads/thumbnail/"
.
$result
->
getFileReference
()
.
".jpg"
;
$data
[
'paths'
][
'zip'
]
=
$this
->
generateUrl
(
'api.songs.download'
,
array
(
'id'
=>
$result
->
getId
()),
UrlGeneratorInterface
::
ABSOLUTE_URL
);
...
...
@@ -148,6 +159,7 @@ class APISongController extends AbstractController
$coverFiles
=
glob
(
$this
->
getParameter
(
'cover_path'
)
.
DIRECTORY_SEPARATOR
.
$result
->
getFileReference
()
.
".png"
);
$oggFiles
=
glob
(
$this
->
getParameter
(
'audio_path'
)
.
DIRECTORY_SEPARATOR
.
$result
->
getFileReference
()
.
"_*.ogg"
);
$mp3Files
=
glob
(
$this
->
getParameter
(
'audio_path'
)
.
DIRECTORY_SEPARATOR
.
$result
->
getFileReference
()
.
"_*.mp3"
);
$zip
=
new
\ZipArchive
;
$zip
->
open
(
$zipLocation
.
$zipName
,
\ZipArchive
::
CREATE
);
...
...
@@ -161,6 +173,12 @@ class APISongController extends AbstractController
$zip
->
addFile
(
$oggFile
,
"AudioClips"
.
DIRECTORY_SEPARATOR
.
$result
->
getFileReference
()
.
"_"
.
$oggIndex
.
".ogg"
);
}
}
if
(
count
(
$mp3Files
)
>
0
)
{
foreach
(
$mp3Files
as
$mp3File
)
{
$mp3Index
=
explode
(
"."
,
explode
(
"_"
,
$mp3File
)[
2
])[
0
];
$zip
->
addFile
(
$mp3File
,
"AudioClips"
.
DIRECTORY_SEPARATOR
.
$result
->
getFileReference
()
.
"_"
.
$mp3Index
.
".mp3"
);
}
}
$zip
->
close
();
$response
=
new
Response
(
file_get_contents
(
$zipLocation
.
$zipName
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment