Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaonan
unify_api2
Commits
961562b0
Commit
961562b0
authored
Mar 08, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix file upload 2024-03-8
parent
46d95b91
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
34 deletions
+43
-34
news_mgr_srv.py
unify_api/modules/qkadmin/service/news_mgr_srv.py
+33
-28
new_mgr.py
unify_api/modules/qkadmin/views/new_mgr.py
+10
-6
No files found.
unify_api/modules/qkadmin/service/news_mgr_srv.py
View file @
961562b0
...
...
@@ -11,41 +11,46 @@ from unify_api.modules.common.procedures.file_operate_pds import upload_file
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
async
def
upload_news_qs
(
request
):
"""附件上传"""
files
=
request
.
files
.
getlist
(
"file"
)
url_article
,
url_cover
=
""
,
""
file_name_lst
=
[
file
.
name
for
file
in
files
]
if
len
(
file_name_lst
)
!=
len
(
set
(
file_name_lst
)):
return
False
,
url_article
,
url_cover
for
i
,
file
in
enumerate
(
files
):
async
def
upload_file_helper
(
file
):
is_upload
,
file_url
=
False
,
""
file_name
=
file
.
name
file_name_lst
=
file_name
.
rsplit
(
"."
,
1
)
if
len
(
file_name_lst
)
<=
1
:
return
False
,
url_article
,
url_cover
return
False
,
file_url
file_body
=
file
.
body
if
file_body
:
if
file
.
body
:
now_dt
=
pendulum
.
now
()
yr
,
month
=
now_dt
.
year
,
now_dt
.
month
file_url
=
f
"{OSS_NEWS}/{yr}/{month}/{uuid4()}.{file_name_lst[1]}"
log
.
info
(
f
"准备上传文件 {file_name} {file_url}"
)
is_upload
=
await
upload_file
(
file
,
file_url
)
if
not
is_upload
:
return
False
,
url_article
,
url_cover
if
i
==
0
:
url_article
=
file_url
else
:
url_cover
=
file_url
else
:
return
is_upload
,
file_url
async
def
upload_news_qs
(
request
):
"""附件上传"""
url_article
,
url_cover
=
""
,
""
news_file
=
request
.
files
.
getlist
(
"file1"
)[
0
]
cover_file
=
request
.
files
.
getlist
(
"file2"
)[
0
]
if
news_file
.
name
==
cover_file
.
name
:
return
False
,
url_article
,
url_cover
news_upload
,
url_article
=
await
upload_file_helper
(
news_file
)
if
news_upload
and
url_article
:
log
.
info
(
f
"上传文章成功, url {url_article}"
)
cover_upload
,
url_cover
=
await
upload_file_helper
(
cover_file
)
if
cover_upload
and
url_cover
:
log
.
info
(
f
"上传文章封面, url {url_cover}"
)
if
all
([
news_file
,
url_article
,
cover_upload
,
url_cover
]):
log
.
info
(
f
"上传文章和封面成功 {url_article} {url_cover}"
)
return
True
,
url_article
,
url_cover
return
False
,
url_article
,
url_cover
async
def
save_news_info
(
news_info
,
news_url
,
cover_url
):
sql
=
"INSERT INTO official_web.news_info (title, news_type, news_url, "
\
...
...
unify_api/modules/qkadmin/views/new_mgr.py
View file @
961562b0
...
...
@@ -4,10 +4,10 @@ DATE:2024/3/5 16:19
"""
from
pot_libs.sanic_api
import
summary
from
pot_libs.logger
import
log
from
unify_api.modules.common.components.common_cps
import
SuccessRsp
from
unify_api.modules.qkadmin.components.news_info_cps
import
(
PubNewsReq
,
NewsPagesReq
,
NewsPagesRsp
,
NewsInfo
,
ReviseNewsReq
,
ReviseNewsSeoReq
NewsPagesReq
,
NewsPagesRsp
,
NewsInfo
,
ReviseNewsReq
,
ReviseNewsSeoReq
)
from
unify_api.modules.qkadmin.service.news_mgr_srv
import
(
upload_news_qs
,
save_news_info
,
load_news_pages
,
update_news_info
,
...
...
@@ -16,12 +16,16 @@ from unify_api.modules.qkadmin.service.news_mgr_srv import (
@
summary
(
"发布文章"
)
async
def
post_publish_news
(
request
,
body
:
PubNewsReq
)
->
SuccessRsp
:
async
def
post_publish_news
(
request
,
*
args
,
**
kwargs
)
->
SuccessRsp
:
log
.
info
(
f
"post_publish_news:{request.form}"
)
log
.
info
(
f
"post_publish_news:{len(request.files.getlist('file1'))}"
)
log
.
info
(
f
"post_publish_news:{len(request.files.getlist('file2'))}"
)
is_success
,
news_url
,
cover_url
=
await
upload_news_qs
(
request
)
if
is_success
:
d_news_info
=
dict
(
title
=
body
.
title
,
author
=
body
.
author
,
pub_time
=
body
.
pub_time
,
news_type
=
int
(
body
.
news_type
))
form
=
request
.
form
d_news_info
=
dict
(
title
=
form
.
title
,
author
=
form
.
author
,
pub_time
=
form
.
pub_time
,
news_type
=
int
(
form
.
news_type
))
await
save_news_info
(
d_news_info
,
news_url
,
cover_url
)
return
SuccessRsp
(
success
=
1
,
message
=
"发布文章成功"
)
...
...
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