Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 43ef879

Browse files
committed
Cleanup code
1 parent 48fe821 commit 43ef879

File tree

7 files changed

+18
-81
lines changed

7 files changed

+18
-81
lines changed

.gitignore

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,17 @@
1-
2-
# Created by https://www.gitignore.io/api/linux,macos,windows,phpstorm,composer,intellij
3-
# Edit at https://www.gitignore.io/?templates=linux,macos,windows,phpstorm,composer,intellij
4-
51
### Composer ###
6-
composer.phar
7-
composer.lock
82
/vendor/
93

104
### Jetbrains ###
115
.idea/**
126

13-
### Linux ###
14-
*~
15-
16-
# temporary files which can be created if a process still has a handle open of a deleted file
17-
.fuse_hidden*
18-
19-
# KDE directory preferences
20-
.directory
21-
22-
# Linux trash folder which might appear on any partition or disk
23-
.Trash-*
24-
25-
# .nfs files are created when an open file is removed but is still being accessed
26-
.nfs*
27-
28-
### macOS ###
29-
# General
30-
.DS_Store
31-
.AppleDouble
32-
.LSOverride
33-
34-
# Icon must end with two \r
35-
Icon
36-
377
# Thumbnails
388
._*
399

40-
# Files that might appear in the root of a volume
41-
.DocumentRevisions-V100
42-
.fseventsd
43-
.Spotlight-V100
44-
.TemporaryItems
45-
.Trashes
46-
.VolumeIcon.icns
47-
.com.apple.timemachine.donotpresent
48-
49-
# Directories potentially created on remote AFP share
50-
.AppleDB
51-
.AppleDesktop
52-
Network Trash Folder
53-
Temporary Items
54-
.apdisk
55-
56-
### Windows ###
57-
# Windows thumbnail cache files
58-
Thumbs.db
59-
ehthumbs.db
60-
ehthumbs_vista.db
61-
62-
# Dump file
63-
*.stackdump
64-
65-
# Folder config file
66-
[Dd]esktop.ini
67-
68-
# Recycle Bin used on file shares
69-
$RECYCLE.BIN/
70-
71-
# Windows Installer files
72-
*.cab
73-
*.msi
74-
*.msix
75-
*.msm
76-
*.msp
77-
7810
# Windows shortcuts
7911
*.lnk
8012

8113
# phpunit
8214
.phpunit.result.cache
8315

84-
# End of https://www.gitignore.io/api/linux,macos,windows,phpstorm,composer,intellij
16+
*.phar
17+
*.lock

download.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22

33
function getCURL(string $id, string $password) {
4+
require_once __DIR__ . '/src/com/carlgo11/tempfiles/Autoload.php';
5+
global $conf;
6+
47
$curl = curl_init();
58
curl_setopt_array($curl, [
6-
CURLOPT_URL => "https://api.tempfiles.carlgo11.com/download/?id={$id}&p={$password}",
9+
CURLOPT_URL => $conf['api-download-url'],
710
CURLOPT_RETURNTRANSFER => TRUE,
811
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2,
912
CURLOPT_CUSTOMREQUEST => 'GET',

src/com/carlgo11/tempfiles/API.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function outputJSON(int $HTTPCode = 200) {
2727
header('Access-Control-Allow-Origin: *'); // Allows other domains to send data to the API.
2828
header('Content-Type: application/json; charset=utf-8');
2929
http_response_code($HTTPCode);
30-
return print(json_encode($this->getMessages(), JSON_PRETTY_PRINT));
30+
$json = json_encode($this->getMessages(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
31+
return print($json);
3132
}
3233

3334
public function getMessages() {

src/com/carlgo11/tempfiles/Autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
or mySQLError($mysql_connection);
1616

1717

18+
1819
/**
1920
* Outputs MySQL error.
2021
*

src/com/carlgo11/tempfiles/api/Delete.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
class Delete extends API
1010
{
1111
public function __construct(string $method) {
12-
if ($method !== 'DELETE') throw new Exception("Bad method. Use DELETE.");
1312

1413
$id = Misc::getVar('id');
1514
$password = Misc::getVar('p');

src/com/carlgo11/tempfiles/api/Upload.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function __construct(string $method) {
5151
if ($password !== NULL) {
5252
if ($fileContent['error'] === 0) {
5353
$file->setContent(file_get_contents($fileContent['tmp_name']));
54-
if (!($upload = DataStorage::uploadFile($file, $password)))
54+
if (!$upload = DataStorage::uploadFile($file, $password))
5555
throw new Exception("Connection to our database failed.");
5656
if (!DataStorage::getFile($file->getID(), $password) instanceof File)
5757
throw new Exception("Unable to verify file integrity.");
@@ -66,14 +66,10 @@ function __construct(string $method) {
6666
}
6767

6868
if (is_bool($upload) && $upload) {
69-
$protocol = "http";
70-
$https = filter_input(INPUT_SERVER, 'HTTPS');
71-
if (isset($https) && $https !== 'off') {
72-
$protocol = "https";
73-
}
69+
global $conf;
7470

7571
// Full URI to download the file
76-
$completeURL = $protocol . "://d.carlgo11.com/" . $file->getID() . "/?p=" . urlencode($password);
72+
$completeURL = sprintf($conf['download-url'], $file->getID(), $password);
7773

7874
$output['success'] = TRUE;
7975
$output['url'] = $completeURL;

src/com/carlgo11/tempfiles/config.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
return [
1010
# Allowed formats <n>MB, <n>GB, <n>TB, <n>PB.
11-
'max-file-size' => '12MB',
11+
'max-file-size' => '100MB',
1212
#'mysql-url' => 'localhost',
1313
'mysql-url' => getenv('ag44jc7aqs2rsup2bb6cx7utc'),
1414
#'mysql-user => 'tempfiles',
@@ -20,5 +20,9 @@
2020
#'mysql-table' => 'files',
2121
'mysql-table' => getenv('rb421p9wniz81ttj7bdgrg0ub'),
2222
# Encryption algorithm to use for encrypting uploads.
23-
'Encryption-Method' => 'aes-256-gcm'
23+
'Encryption-Method' => 'aes-256-gcm',
24+
# Download URL
25+
'download-url' => 'https://d.carlgo11.com/%1$s/?p=%2$s',
26+
# API Download URL
27+
'api-download-url' => 'https://api.tempfiles.carlgo11.com/download/?id=%1$s&p=%1$s'
2428
];

0 commit comments

Comments
 (0)