You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							166 lines
						
					
					
						
							3.6 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							166 lines
						
					
					
						
							3.6 KiB
						
					
					
				
								'use strict';
							 | 
						|
								
							 | 
						|
								async function addEditFile (ctx, next) {
							 | 
						|
								   let message = '添加文件夹失败'
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const data = ctx.request.body;
							 | 
						|
								      const { higherFileId, fileName, projectId, type } = data
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								      let onefind = await models.ProjectFolder.findOne({
							 | 
						|
								         where: {
							 | 
						|
								            higherFileId: higherFileId || null,
							 | 
						|
								            fileName,
							 | 
						|
								            projectId,
							 | 
						|
								            type
							 | 
						|
								         }
							 | 
						|
								      })
							 | 
						|
								      if (onefind) {
							 | 
						|
								         message = '已有同层级文件夹'
							 | 
						|
								         throw message
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								      if (data && data.id) {
							 | 
						|
								         await models.ProjectFolder.update(data, {
							 | 
						|
								            where: {
							 | 
						|
								               id: data.id
							 | 
						|
								            }
							 | 
						|
								         })
							 | 
						|
								      } else {
							 | 
						|
								         await models.ProjectFolder.create(data)
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      ctx.status = 204;
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         "message": message
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function fileList (ctx, next) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { projectId, type } = ctx.query;
							 | 
						|
								
							 | 
						|
								      let options = { where: {}, }
							 | 
						|
								      if (projectId) {
							 | 
						|
								         options.where.projectId = projectId
							 | 
						|
								      }
							 | 
						|
								      if (type) {
							 | 
						|
								         options.where.type = type
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      let res = await models.ProjectFolder.findAll(options)
							 | 
						|
								
							 | 
						|
								      ctx.status = 200;
							 | 
						|
								      ctx.body = res || []
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         "message": '添加文件夹失败'
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function delFile (ctx, next) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { id } = ctx.params;
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								      await models.ProjectFolder.destroy({ where: { id } })
							 | 
						|
								
							 | 
						|
								      ctx.status = 204;
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         "message": '删除文件夹失败'
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function addFile (ctx, next) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const data = ctx.request.body;
							 | 
						|
								
							 | 
						|
								      await models.ProjectFolderFile.create(data)
							 | 
						|
								
							 | 
						|
								      ctx.status = 204;
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         "message": '添加文件夹失败'
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function folderFileList (ctx, next) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { fileId, limit, page, keyword } = ctx.query;
							 | 
						|
								
							 | 
						|
								      let options = { where: {}, }
							 | 
						|
								      if (JSON.parse(fileId).length) {
							 | 
						|
								         options.where.fileId = { $in: JSON.parse(fileId) }
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      if (keyword) {
							 | 
						|
								         options.where.name = { $ilike: `%${keyword}%` }
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      if (limit) {
							 | 
						|
								         options.limit = Number(limit)
							 | 
						|
								      }
							 | 
						|
								      if (page && limit) {
							 | 
						|
								         options.offset = Number(page) * Number(limit)
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      let res = await models.ProjectFolderFile.findAndCountAll(options)
							 | 
						|
								
							 | 
						|
								      ctx.status = 200
							 | 
						|
								      ctx.body = res || {}
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         "message": '添加文件列表失败'
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								async function delfolderFile (ctx, next) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { id } = ctx.params;
							 | 
						|
								
							 | 
						|
								      await models.ProjectFolderFile.destroy({ where: { id } })
							 | 
						|
								
							 | 
						|
								      ctx.status = 204;
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         "message": '删除文件失败'
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								module.exports = {
							 | 
						|
								   addEditFile,
							 | 
						|
								   fileList,
							 | 
						|
								   delFile,
							 | 
						|
								   addFile,
							 | 
						|
								   folderFileList,
							 | 
						|
								   delfolderFile
							 | 
						|
								}
							 |