Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rbl-cms
cms-backend
Commits
63907b2e
Commit
63907b2e
authored
4 months ago
by
theword
Browse files
Options
Download
Email Patches
Plain Diff
fix error page when download 50tawi
parent
bd3a1576
main
dev
feature/download-50tawi
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main/java/com/b3/rbl/compensation/rest/ReportRestApi.java
+25
-8
...main/java/com/b3/rbl/compensation/rest/ReportRestApi.java
src/main/resources/templates/error/401.html
+1
-1
src/main/resources/templates/error/401.html
src/main/resources/templates/error/404.html
+8
-10
src/main/resources/templates/error/404.html
src/main/resources/templates/error/500.html
+1
-1
src/main/resources/templates/error/500.html
with
35 additions
and
20 deletions
+35
-20
src/main/java/com/b3/rbl/compensation/rest/ReportRestApi.java
View file @
63907b2e
...
...
@@ -5,11 +5,13 @@ import javax.servlet.http.HttpServletResponse;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.b3.rbl.compensation.controller.BaseController
;
import
com.b3.rbl.compensation.service.JwtUtil
;
...
...
@@ -60,21 +62,36 @@ public class ReportRestApi extends BaseController {
}
@GetMapping
(
"/download50tawi"
)
public
ResponseEntity
<
byte
[]
>
downloadReport50tawi
(
@RequestParam
(
"downloadPath"
)
String
downloadPath
,
public
ResponseEntity
<
?
>
downloadReport50tawi
(
@RequestParam
(
"downloadPath"
)
String
downloadPath
,
@RequestParam
(
"token"
)
String
token
,
@RequestParam
(
"filename"
)
String
filename
,
@RequestParam
(
"mimeType"
)
String
mimeType
)
throws
Exception
{
@RequestParam
(
"mimeType"
)
String
mimeType
,
RedirectAttributes
redirectAttrs
)
throws
Exception
{
if
(
jwtUtil
.
isTokenExpired
(
token
))
{
super
.
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
// HTTP 401.
return
null
;
}
String
path
=
PATH
+
reportPath50tawi
+
"/"
+
downloadPath
.
replace
(
" "
,
"%20"
)
+
":/content"
;
byte
[]
report
=
onedriveService
.
getFileFromUrl
(
path
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"Content-Disposition"
,
"inline; filename="
+
filename
);
headers
.
set
(
HttpHeaders
.
CONTENT_TYPE
,
mimeType
+
";charset=utf-8"
);
try
{
byte
[]
report
=
onedriveService
.
getFileFromUrl
(
path
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"Content-Disposition"
,
"inline; filename="
+
filename
);
headers
.
set
(
HttpHeaders
.
CONTENT_TYPE
,
mimeType
+
";charset=utf-8"
);
return
ResponseEntity
.
ok
().
headers
(
headers
).
body
(
report
);
}
catch
(
Exception
ex
)
{
redirectAttrs
.
addFlashAttribute
(
"disable_code"
,
""
);
redirectAttrs
.
addFlashAttribute
(
"header"
,
"File Not Found"
);
try
{
redirectAttrs
.
addFlashAttribute
(
"error_message"
,
"ไม่พบ 50 ทวิ สำหรับรหัสตัวแทน [ "
+
filename
.
split
(
"_"
)[
0
]
+
" ]"
);
}
catch
(
Exception
e
)
{
redirectAttrs
.
addFlashAttribute
(
"error_message"
,
"ไม่พบ 50 ทวิ"
);
}
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"location"
,
"404.html"
);
return
new
ResponseEntity
<
String
>(
headers
,
HttpStatus
.
FOUND
);
}
return
ResponseEntity
.
ok
().
headers
(
headers
).
body
(
report
);
}
}
This diff is collapsed.
Click to expand it.
src/main/resources/templates/error/401.html
View file @
63907b2e
...
...
@@ -88,7 +88,7 @@
<h3>
Unauthorized
</h3>
<h2>
You are not authorized to access this page!
</h2>
<!-- use window.history.back(); to go back -->
<a
href=
"./"
><button>
Go Back
</button></a>
<!--
<a href="./"><button>Go Back</button></a>
-->
</div>
<scipt>
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/templates/error/404.html
View file @
63907b2e
<!DOCTYPE html>
<html
lang=
"th"
>
<html
lang=
"th"
>
<head>
<title>
Error page
</title>
<meta
charset=
"utf-8"
/>
...
...
@@ -82,16 +83,13 @@
}
</style>
</head>
<body>
<body>
<div
class=
"message"
>
<h1>
404
</h1>
<h3>
Page Not Found
</h3>
<h2>
The page you are looking for not avaible!
</h2>
<h1
th:text=
"${disable_code}?: '404'"
>
404
</h1>
<h3
th:text=
"${header} ?: 'Page Not Found'"
>
Page Not Found
</h3>
<h2
th:text=
"${error_message} ?: 'The page you are looking for not avaible!'"
>
The page you are looking for not avaible!
</h2>
<!-- use window.history.back(); to go back -->
<a
href=
"./"
><button>
Go Back
</button></a>
<!--
<a href="./"><button>Go Back</button></a>
-->
</div>
<scipt>
</scipt>
</body>
</html>
This diff is collapsed.
Click to expand it.
src/main/resources/templates/error/500.html
View file @
63907b2e
...
...
@@ -88,7 +88,7 @@
<h3>
Internal Server Error
</h3>
<h2>
An error occurred and your request couldn’t be completed. Please try again.
</h2>
<!-- use window.history.back(); to go back -->
<button
onclick=
"window.history.back()"
>
Go Back
</button>
<!--
<button onclick="window.history.back()">Go Back</button>
-->
</div>
<scipt>
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help