Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sfcode
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush
sfcode
Commits
2ce9ffeb
Commit
2ce9ffeb
authored
Dec 06, 2020
by
Ayush
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug file upload backend
parent
82a0168e
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
51 additions
and
51 deletions
+51
-51
backend/filesave.php
backend/filesave.php
+32
-34
backend/register.php
backend/register.php
+5
-5
src/app/arena/arena.component.ts
src/app/arena/arena.component.ts
+2
-2
src/app/auth.guard.ts
src/app/auth.guard.ts
+1
-1
src/app/file.service.ts
src/app/file.service.ts
+4
-6
src/app/file.ts
src/app/file.ts
+1
-1
src/app/file/file.component.html
src/app/file/file.component.html
+1
-1
src/app/file/file.component.ts
src/app/file/file.component.ts
+4
-0
src/app/ide/ide.component.ts
src/app/ide/ide.component.ts
+1
-1
No files found.
backend/filesave.php
View file @
2ce9ffeb
...
@@ -3,43 +3,41 @@
...
@@ -3,43 +3,41 @@
include_once
(
"database.php"
);
include_once
(
"database.php"
);
$postData
=
file_get_contents
(
"php://input"
);
$postData
=
file_get_contents
(
"php://input"
);
if
(
isset
(
$postData
)
&&
!
empty
(
$postData
))
{
if
(
isset
(
$postData
)
&&
!
empty
(
$postData
))
{
$request
=
json_decode
(
$postData
);
$request
=
json_decode
(
$postData
);
$username
=
trim
(
$request
->
File
.
id
);
$username
=
trim
(
$request
->
username
);
$data
=
trim
(
$request
->
File
.
text
);
$data
=
trim
(
$request
->
text
);
$filename
=
trim
(
$request
->
File
.
filename
);
$filename
=
trim
(
$request
->
filename
);
$lang
=
trim
(
$request
->
File
.
language
);
$lang
=
trim
(
$request
->
language
);
$path
=
trim
(
$request
->
File
.
path
)
.
'/'
.
$filename
;
$path
=
'../users/'
.
$username
.
'/'
.
trim
(
$request
->
path
)
.
'/'
.
$filename
.
$lang
;
if
(
file_exists
(
$path
))
{
if
(
file_exists
(
$path
))
{
$msg
=
"file already exists"
;
$msg
=
"file already exists"
;
clearstatcache
();
clearstatcache
();
echo
json_encode
(
$msg
);
echo
json_encode
(
$msg
);
}
}
else
{
else
{
// $sql1 = "SELECT n_files from userdata where username = $username";
$sql1
=
"SELECT n_files from userdata where username =
$username
"
;
// $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
$sql2
=
"UPDATE userdata SET n_files = n_files+1 WHERE username =
$username
"
;
// $result = mysqli_query($mysqli, $sql1);
$result
=
mysqli_query
(
$mysqli
,
$sql1
);
// if($result == 10){
if
(
$result
==
10
){
// $msg = "maximum limit(10) exceeded";
$msg
=
"maximum limit(10) exceeded"
;
// echo json_encode($msg);
echo
json_encode
(
$msg
);
// }
}
// else{
else
{
// if($result = mysqli_query($mysqli, $sql2)) {
if
(
$result
=
mysqli_query
(
$mysqli
,
$sql2
))
{
$myfile
=
fopen
(
$path
,
"w"
);
$myfile
=
fopen
(
$path
,
"w"
);
fwrite
(
$myfile
,
$data
);
fwrite
(
$myfile
,
$data
);
fclose
(
$myfile
);
fclose
(
$myfile
);
$msg
=
"file successfully uploaded"
;
$msg
=
"file successfully uploaded"
;
clearstatcache
();
clearstatcache
();
echo
json_encode
(
$msg
);
echo
json_encode
(
$msg
);
}
//
}
else
{
//
else{
http_response_code
(
404
);
//
http_response_code(404);
}
//
}
}
}
}
}
}
?>
?>
backend/register.php
View file @
2ce9ffeb
...
@@ -19,7 +19,7 @@ if (isset($postData) && !empty($postData)) {
...
@@ -19,7 +19,7 @@ if (isset($postData) && !empty($postData)) {
'username'
=>
$username
'username'
=>
$username
];
];
mkdir
(
$authData
[
'id
'
]);
mkdir
(
'../users/'
.
$authData
[
'username
'
]);
echo
json_encode
(
$authData
);
echo
json_encode
(
$authData
);
}
}
...
...
src/app/arena/arena.component.ts
View file @
2ce9ffeb
...
@@ -59,11 +59,11 @@ export class ArenaComponent implements OnInit {
...
@@ -59,11 +59,11 @@ export class ArenaComponent implements OnInit {
const
username
=
JSON
.
parse
(
this
.
apiService
.
getToken
()).
username
;
const
username
=
JSON
.
parse
(
this
.
apiService
.
getToken
()).
username
;
for
(
const
ext
of
extensions
)
{
for
(
const
ext
of
extensions
)
{
this
.
files
.
push
({
this
.
files
.
push
({
id
:
null
,
username
,
username
,
filename
,
filename
,
language
:
ext
,
language
:
ext
,
text
:
''
text
:
''
,
path
:
'
/
'
});
});
}
}
...
...
src/app/auth.guard.ts
View file @
2ce9ffeb
...
@@ -18,7 +18,7 @@ export class AuthGuard implements CanActivate {
...
@@ -18,7 +18,7 @@ export class AuthGuard implements CanActivate {
return
this
.
isLogin
(
routeUrl
);
return
this
.
isLogin
(
routeUrl
);
}
}
isLogin
(
routeUrl
:
string
)
{
isLogin
(
routeUrl
:
string
)
:
boolean
{
if
(
this
.
dataService
.
isLoggedIn
())
{
if
(
this
.
dataService
.
isLoggedIn
())
{
return
true
;
return
true
;
}
}
...
...
src/app/file.service.ts
View file @
2ce9ffeb
...
@@ -9,7 +9,7 @@ import {HttpClient} from '@angular/common/http';
...
@@ -9,7 +9,7 @@ import {HttpClient} from '@angular/common/http';
})
})
export
class
FileService
{
export
class
FileService
{
baseApiUrl
=
'
http
s://file.io
'
;
baseApiUrl
=
'
http
://localhost/sfcode/backend/filesave.php
'
;
constructor
(
private
http
:
HttpClient
)
{
constructor
(
private
http
:
HttpClient
)
{
}
}
...
@@ -23,10 +23,10 @@ export class FileService {
...
@@ -23,10 +23,10 @@ export class FileService {
for
(
const
item
of
arr
)
{
for
(
const
item
of
arr
)
{
ret
.
push
({
ret
.
push
({
username
:
''
,
username
:
''
,
id
:
item
,
filename
:
'
lambda
'
,
filename
:
'
lambda
'
,
language
:
'
.cpp
'
,
language
:
'
.cpp
'
,
text
:
'
Random Shit
'
text
:
'
Random Shit
'
,
path
:
'
/
'
});
});
}
}
...
@@ -34,9 +34,7 @@ export class FileService {
...
@@ -34,9 +34,7 @@ export class FileService {
}
}
upload
(
file
):
Observable
<
any
>
{
upload
(
file
):
Observable
<
any
>
{
const
formData
=
new
FormData
();
return
this
.
http
.
post
(
this
.
baseApiUrl
,
file
);
formData
.
append
(
'
file
'
,
new
Blob
([
new
TextEncoder
().
encode
(
file
)],
{
type
:
'
application/json
'
}),
file
.
name
);
return
this
.
http
.
post
(
this
.
baseApiUrl
,
formData
);
}
}
}
}
src/app/file.ts
View file @
2ce9ffeb
export
interface
File
{
export
interface
File
{
id
:
number
;
username
:
string
;
username
:
string
;
filename
:
string
;
filename
:
string
;
language
:
string
;
language
:
string
;
text
:
string
;
text
:
string
;
path
:
string
;
}
}
src/app/file/file.component.html
View file @
2ce9ffeb
...
@@ -58,7 +58,7 @@
...
@@ -58,7 +58,7 @@
</div>
</div>
<p
*ngIf=
"!loading"
>
<p
*ngIf=
"!loading"
>
<button
(click)=
"uploadPopupActive = false;"
id=
"upload-cancel-btn"
>
Close
</button>
<button
(click)=
"uploadPopupActive = false;"
id=
"upload-cancel-btn"
>
Close
</button>
<button
(click)=
"onUpload()"
id=
"file-upload-btn"
>
Upload
</button>
<button
(click)=
"onUpload()"
id=
"file-upload-btn"
[class.disabled]=
"fileToUpload == null || fileToUpload == undefined"
>
Upload
</button>
</p>
</p>
<p
*ngIf=
"loading"
style=
"margin-top: 20px; text-align: center"
>
<p
*ngIf=
"loading"
style=
"margin-top: 20px; text-align: center"
>
Uploading...
Uploading...
...
...
src/app/file/file.component.ts
View file @
2ce9ffeb
...
@@ -30,9 +30,13 @@ export class FileComponent implements OnInit {
...
@@ -30,9 +30,13 @@ export class FileComponent implements OnInit {
onChange
(
event
):
void
{
onChange
(
event
):
void
{
this
.
fileToUpload
=
event
.
target
.
files
[
0
];
this
.
fileToUpload
=
event
.
target
.
files
[
0
];
console
.
log
(
this
.
fileToUpload
);
}
}
onUpload
():
void
{
onUpload
():
void
{
if
((
document
.
getElementById
(
'
file-upload-input
'
)
as
HTMLInputElement
).
value
===
''
)
{
return
;
}
this
.
loading
=
true
;
this
.
loading
=
true
;
console
.
log
(
this
.
fileToUpload
);
console
.
log
(
this
.
fileToUpload
);
...
...
src/app/ide/ide.component.ts
View file @
2ce9ffeb
...
@@ -23,11 +23,11 @@ export class IdeComponent implements OnInit {
...
@@ -23,11 +23,11 @@ export class IdeComponent implements OnInit {
isUploading
=
false
;
isUploading
=
false
;
isUpToDate
=
false
;
isUpToDate
=
false
;
file
:
File
=
{
file
:
File
=
{
id
:
null
,
filename
:
'
Untitled
'
,
filename
:
'
Untitled
'
,
language
:
'
.cpp
'
,
language
:
'
.cpp
'
,
text
:
''
,
text
:
''
,
username
:
JSON
.
parse
(
this
.
apiService
.
getToken
()).
username
,
username
:
JSON
.
parse
(
this
.
apiService
.
getToken
()).
username
,
path
:
'
/
'
};
};
@
ViewChild
(
InputComponent
)
inputField
;
@
ViewChild
(
InputComponent
)
inputField
;
@
ViewChild
(
IdeCompileComponent
)
runField
;
@
ViewChild
(
IdeCompileComponent
)
runField
;
...
...
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