Merge pull request #205 from ivandiazwm/master

Fix image attachments issue, add build script
This commit is contained in:
Ivan Diaz 2018-05-14 19:43:54 -03:00 committed by GitHub
commit d0809ddc50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 4 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ server/files/
!server/files/.gitkeep
server/.dbdata
server/.fakemail
dist/

View File

@ -61,6 +61,9 @@ Server api runs on `http://localhost:8080/`
Also, there's a *phpmyadmin* instance running on `http://localhost:6060/`,
you can access with the username `root` and empty password
##### Building
Once you've installed dependencies for frontend and backend, you can run `./build.sh` and it will generate a zip file inside `dist/` ready for distribution. You can use this file to install OpenSupports on a serving following the [installation instructions](https://github.com/opensupports/opensupports/wiki/Installation)
##### BACKEND API RUBY TESTING
1. Go to tests folder: `cd opensupports/tests`

38
build.sh Executable file
View File

@ -0,0 +1,38 @@
echo "1/3 Building frontend..."
cd client
gulp prod --api
rm build/index.html
echo "2/3 Creating api folder..."
cd ../server
rm -rf files
mkdir files
cd ..
mkdir api
cp server/index.php api
cp server/.htaccess api
cp server/composer.json api
cp server/composer.lock api
cp -R server/controllers api
cp -R server/data api
cp -R server/libs api
cp -R server/models api
cp -R server/vendor api
mkdir api/files
touch api/files/.keep
echo -n > api/config.php
chmod -R 755 .
echo "3/3 Generating zip..."
cd client/build
zip opensupports_dev.zip index.php
zip -u opensupports_dev.zip .htaccess
zip -u opensupports_dev.zip css/main.css
zip -u opensupports_dev.zip js/main.js
zip -ur opensupports_dev.zip fonts
zip -ur opensupports_dev.zip images
mv opensupports_dev.zip ../..
cd ../..
zip -ur opensupports_dev.zip api
rm -rf dist
mkdir dist
mv opensupports_dev.zip dist
rm -rf api

View File

@ -19,9 +19,9 @@ class FileDownloader extends FileManager {
if(file_exists($fullFilePath) && is_file($fullFilePath)) {
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($fullFilePath));
header('Content-Disposition: filename='. $this->getFileName());
header('Content-Type: ' . $this->getFileContentType());
header('Content-Length: ' . filesize($fullFilePath));
header('Content-Disposition: filename=' . $this->getFileName());
flush();
$file = fopen($fullFilePath, 'r');
@ -37,4 +37,18 @@ class FileDownloader extends FileManager {
public function eraseFile() {
unlink($this->getLocalPath() . $this->getFileName());
}
}
public function getFileContentType() {
$fileExtension = substr($this->getFileName(), -3);
$contentTypes = [
'jpg' => 'image/jpeg',
'gif' => 'image/fig',
'png' => 'image/png',
'default' => 'application/octet-stream',
];
return $contentTypes[
array_key_exists($fileExtension, $contentTypes) ? $fileExtension : 'default'
];
}
}