1414import github .nooblong .download .api .AddQueueRequest ;
1515import github .nooblong .download .bilibili .BilibiliClient ;
1616import github .nooblong .download .bilibili .SimpleVideoInfo ;
17+ import github .nooblong .download .entity .CidName ;
1718import github .nooblong .download .entity .Subscribe ;
1819import github .nooblong .download .entity .UploadDetail ;
1920import github .nooblong .download .entity .UserVoicelist ;
3435import java .util .stream .Collectors ;
3536
3637@ RestController
37- @ RequestMapping ("/uploadDetail " )
38+ @ RequestMapping ("/upload " )
3839public class UploadDetailController {
3940
4041 final UploadDetailService uploadDetailService ;
@@ -59,51 +60,7 @@ public UploadDetailController(UploadDetailService uploadDetailService,
5960 this .redisTemplate = redisTemplate ;
6061 }
6162
62- @ Cacheable (value = "uploadDetail/listVoicelist" )
63- @ GetMapping ("/listVoicelist" )
64- public Result <List <UserVoicelist >> listVoicelist (@ RequestParam (name = "username" , required = false ) String username ) {
65- List <SysUser > userList = Db .list (Wrappers .lambdaQuery (SysUser .class )
66- .eq (username != null , SysUser ::getUsername , username ));
67- if (userList .isEmpty ()) {
68- return Result .ok ("ok" , new ArrayList <>());
69- }
70- List <UserVoicelist > list = Db .list (Wrappers .lambdaQuery (UserVoicelist .class )
71- .in (UserVoicelist ::getUserId , userList .stream ().map (SysUser ::getId ).collect (Collectors .toList ())));
72- for (UserVoicelist userVoicelist : list ) {
73- String voiceNumKey = userVoicelist .getVoicelistId () + ":voiceNum" ;
74- String subscribeNumKey = userVoicelist .getVoicelistId () + ":subscribeNum" ;
75- if (Boolean .TRUE .equals (redisTemplate .hasKey (voiceNumKey ))) {
76- String s = redisTemplate .opsForValue ().get (voiceNumKey );
77- userVoicelist .setUploadCount (s == null ? 0 : Integer .parseInt (s ));
78- } else {
79- long count = Db .count (Wrappers .lambdaQuery (UploadDetail .class )
80- .eq (UploadDetail ::getVoiceListId , userVoicelist .getVoicelistId ()));
81- userVoicelist .setUploadCount ((int ) count );
82- redisTemplate .opsForValue ().set (voiceNumKey , String .valueOf (count ), 1 , TimeUnit .MINUTES );
83- }
84- if (Boolean .TRUE .equals (redisTemplate .hasKey (subscribeNumKey ))) {
85- String s = redisTemplate .opsForValue ().get (subscribeNumKey );
86- userVoicelist .setSubscribeNum (s == null ? 0 : Integer .parseInt (s ));
87- } else {
88- long count = Db .count (Wrappers .lambdaQuery (Subscribe .class )
89- .eq (Subscribe ::getVoiceListId , userVoicelist .getVoicelistId ()));
90- userVoicelist .setSubscribeNum ((int ) count );
91- redisTemplate .opsForValue ().set (subscribeNumKey , String .valueOf (count ), 1 , TimeUnit .MINUTES );
92- }
93- }
94- return Result .ok ("ok" , list );
95- }
96-
97- @ CacheEvict (value = "uploadDetail/listVoicelist" , allEntries = true )
98- @ GetMapping ("/refreshVoiceList" )
99- public Result <String > refreshVoiceList () {
100- SysUser sysUser = JwtUtil .verifierFromContext ();
101- userVoicelistService .syncUserVoicelist (sysUser .getId ());
102- return Result .ok ("ok" );
103- }
104-
105- @ Cacheable (value = "uploadDetail/list" )
106- @ GetMapping ("/list" )
63+ @ GetMapping
10764 public Result <IPage <UploadDetail >> list (@ RequestParam (name = "pageNo" ) int pageNo ,
10865 @ RequestParam (name = "pageSize" ) int pageSize ,
10966 @ RequestParam (name = "column" , required = false ) String column ,
@@ -169,13 +126,49 @@ public Result<IPage<UploadDetail>> list(@RequestParam(name = "pageNo") int pageN
169126 return Result .ok ("查询成功" , page );
170127 }
171128
172- @ GetMapping ("/getById" )
173- public Result <UploadDetail > get (@ RequestParam (name = "id" ) Long id ) {
174- return Result .ok ("ok" , Db .getById (id , UploadDetail .class ));
129+ @ PostMapping
130+ public Result <String > addQueue (@ RequestBody UploadDetail req ) {
131+ Long userId = JwtUtil .verifierFromContext ().getId ();
132+ List <SysUser > userList = SimpleQuery .list (Wrappers .lambdaQuery (SysUser .class )
133+ .eq (SysUser ::getId , userId ), i -> i );
134+ boolean isAdmin = !userList .isEmpty () && userList .get (0 ).getIsAdmin () == 1 ;
135+ List <UserVoicelist > userVoicelistList = userVoicelistService .lambdaQuery ()
136+ .eq (UserVoicelist ::getUserId , userId )
137+ .list ();
138+ Map <Long , UserVoicelist > userVoicelistMap =
139+ SimpleQuery .list2Map (userVoicelistList , UserVoicelist ::getVoicelistId , i -> i );
140+ if (req .getCidNames () != null && !req .getCidNames ().isEmpty ()) {
141+ for (CidName cidName : req .getCidNames ()) {
142+ Assert .isTrue (StrUtil .isNotBlank (req .getBvid ()), "bvid为空" );
143+ Assert .isTrue (req .getVoiceListId () != null && req .getVoiceListId () != 0 , "voiceListId为空" );
144+ Assert .notNull (userVoicelistMap .get (req .getVoiceListId ()), "不是你的voiceListId" );
145+ SimpleVideoInfo simpleVideoInfo = bilibiliClient .getSimpleVideoInfoByBvidOrUrl (req .getBvid ());
146+ UploadDetail uploadDetail = new UploadDetail ();
147+ uploadDetail .setBvid (simpleVideoInfo .getBvid ());
148+ uploadDetail .setCid (cidName .getCid ());
149+ uploadDetail .setVoiceListId (req .getVoiceListId ());
150+ uploadDetail .setUseVideoCover (req .getUseVideoCover ());
151+ uploadDetail .setBeginSec (req .getBeginSec ());
152+ uploadDetail .setEndSec (req .getEndSec ());
153+ uploadDetail .setOffset (req .getOffset ());
154+ uploadDetail .setUploadName (cidName .getName ());
155+ uploadDetail .setPrivacy (req .getPrivacy ());
156+ uploadDetail .setPriority (isAdmin ? 999L : 10L );
157+ uploadDetail .setBitrate (req .getBitrate ());
158+ uploadDetail .setUserId (userId );
159+ uploadDetail .setCrack (req .getCrack () == null ? 0L : 1L );
160+ if (req .getCrack () != null && req .getCrack () == 1 ) {
161+ Assert .isTrue (isAdmin , "unsupported" );
162+ }
163+ Db .save (uploadDetail );
164+ }
165+ } else {
166+ throw new RuntimeException ("没有分p信息" );
167+ }
168+ return Result .ok ("添加队列成功" );
175169 }
176170
177- @ CacheEvict (value = "uploadDetail/list" , allEntries = true )
178- @ PostMapping ("/edit" )
171+ @ PutMapping
179172 public Result <UploadDetail > update (@ RequestBody UploadDetail uploadDetail ) {
180173 Long userId = JwtUtil .verifierFromContext ().getId ();
181174 UploadDetail byId = uploadDetailService .getById (uploadDetail .getId ());
@@ -184,6 +177,43 @@ public Result<UploadDetail> update(@RequestBody UploadDetail uploadDetail) {
184177 return Result .ok ("ok" , byId );
185178 }
186179
180+ @ GetMapping ("/listVoicelist" )
181+ public Result <IPage <UserVoicelist >> listVoicelist (@ RequestParam (name = "username" , required = false ) String username ,
182+ @ RequestParam (name = "pageNo" , defaultValue = "1" , required = false ) Integer pageNo ,
183+ @ RequestParam (name = "pageSize" , defaultValue = "10" , required = false ) Integer pageSize ) {
184+ List <SysUser > userList = Db .list (Wrappers .lambdaQuery (SysUser .class )
185+ .eq (username != null , SysUser ::getUsername , username ));
186+ if (userList .isEmpty ()) {
187+ return Result .ok ("ok" , new Page <>());
188+ }
189+ IPage <UserVoicelist > page = Db .page (new Page <>(pageNo , pageSize ),
190+ Wrappers .lambdaQuery (UserVoicelist .class )
191+ .in (UserVoicelist ::getUserId , userList .stream ().map (SysUser ::getId ).collect (Collectors .toList ()))
192+ .orderByDesc (UserVoicelist ::getVoicelistId ));
193+ for (UserVoicelist userVoicelist : page .getRecords ()) {
194+ long count = Db .count (Wrappers .lambdaQuery (UploadDetail .class )
195+ .eq (UploadDetail ::getVoiceListId , userVoicelist .getVoicelistId ()));
196+ userVoicelist .setUploadCount ((int ) count );
197+ long count2 = Db .count (Wrappers .lambdaQuery (Subscribe .class )
198+ .eq (Subscribe ::getVoiceListId , userVoicelist .getVoicelistId ()));
199+ userVoicelist .setSubscribeNum ((int ) count2 );
200+ }
201+ return Result .ok ("ok" , page );
202+ }
203+
204+ @ CacheEvict (value = "uploadDetail/listVoicelist" , allEntries = true )
205+ @ GetMapping ("/refreshVoiceList" )
206+ public Result <String > refreshVoiceList () {
207+ SysUser sysUser = JwtUtil .verifierFromContext ();
208+ userVoicelistService .syncUserVoicelist (sysUser .getId ());
209+ return Result .ok ("ok" );
210+ }
211+
212+ @ GetMapping ("/getById" )
213+ public Result <UploadDetail > get (@ RequestParam (name = "id" ) Long id ) {
214+ return Result .ok ("ok" , Db .getById (id , UploadDetail .class ));
215+ }
216+
187217 @ CacheEvict (value = "uploadDetail/list" , allEntries = true )
188218 @ GetMapping ("/delete" )
189219 public Result <Boolean > delete (@ RequestParam (name = "id" ) Long id ) {
@@ -194,45 +224,6 @@ public Result<Boolean> delete(@RequestParam(name = "id") Long id) {
194224 return Result .ok ("ok" );
195225 }
196226
197- @ CacheEvict (value = "uploadDetail/list" , allEntries = true )
198- @ PostMapping ("/add" )
199- public Result <String > addQueue (@ RequestBody AddQueueRequest reqs ) {
200- Long userId = JwtUtil .verifierFromContext ().getId ();
201- List <SysUser > userList = SimpleQuery .list (Wrappers .lambdaQuery (SysUser .class )
202- .eq (SysUser ::getId , userId ), i -> i );
203- boolean isAdmin = !userList .isEmpty () && userList .get (0 ).getIsAdmin () == 1 ;
204- List <UserVoicelist > userVoicelistList = userVoicelistService .lambdaQuery ()
205- .eq (UserVoicelist ::getUserId , userId )
206- .list ();
207- Map <Long , UserVoicelist > userVoicelistMap =
208- SimpleQuery .list2Map (userVoicelistList , UserVoicelist ::getVoicelistId , i -> i );
209- for (UploadDetail req : reqs .getUploadDetails ()) {
210- Assert .isTrue (StrUtil .isNotBlank (req .getBvid ()), "bvid empty" );
211- Assert .isTrue (req .getVoiceListId () != null , "voiceListId empty" );
212- Assert .notNull (userVoicelistMap .get (req .getVoiceListId ()), "not owner" );
213- SimpleVideoInfo simpleVideoInfo = bilibiliClient .getSimpleVideoInfoByBvidOrUrl (req .getBvid ());
214- UploadDetail uploadDetail = new UploadDetail ();
215- uploadDetail .setBvid (simpleVideoInfo .getBvid ());
216- uploadDetail .setCid (req .getCid ());
217- uploadDetail .setVoiceListId (req .getVoiceListId ());
218- uploadDetail .setUseVideoCover (req .getUseVideoCover ());
219- uploadDetail .setBeginSec (req .getBeginSec ());
220- uploadDetail .setEndSec (req .getEndSec ());
221- uploadDetail .setOffset (req .getOffset ());
222- uploadDetail .setUploadName (req .getUploadName ());
223- uploadDetail .setPrivacy (req .getPrivacy ());
224- uploadDetail .setPriority (isAdmin ? 999L : 10L );
225- uploadDetail .setBitrate (req .getBitrate ());
226- uploadDetail .setUserId (userId );
227- uploadDetail .setCrack (req .getCrack ());
228- if (req .getCrack () == 1 ) {
229- Assert .isTrue (isAdmin , "crack error" );
230- }
231- Db .save (uploadDetail );
232- }
233- return Result .ok ("添加队列成功" );
234- }
235-
236227 @ CacheEvict (value = "uploadDetail/list" , allEntries = true )
237228 @ GetMapping ("/restartJob" )
238229 public Result <String > restartJob (@ RequestParam (name = "id" ) Long id ) {
0 commit comments