Resolve #2165
This commit is contained in:
		
							parent
							
								
									3ae42d9b85
								
							
						
					
					
						commit
						ebceffba1e
					
				
					 3 changed files with 71 additions and 37 deletions
				
			
		| 
						 | 
					@ -19,21 +19,26 @@
 | 
				
			||||||
				</ui-select>
 | 
									</ui-select>
 | 
				
			||||||
			</ui-horizon-group>
 | 
								</ui-horizon-group>
 | 
				
			||||||
			<div class="kidvdlkg" v-for="file in files">
 | 
								<div class="kidvdlkg" v-for="file in files">
 | 
				
			||||||
				<div>
 | 
									<div @click="file._open = !file._open">
 | 
				
			||||||
					<div class="thumbnail" :style="thumbnail(file)"></div>
 | 
					 | 
				
			||||||
				</div>
 | 
					 | 
				
			||||||
				<div>
 | 
					 | 
				
			||||||
					<header>
 | 
					 | 
				
			||||||
						<b>{{ file.name }}</b>
 | 
					 | 
				
			||||||
						<span class="username">@{{ file.user | acct }}</span>
 | 
					 | 
				
			||||||
					</header>
 | 
					 | 
				
			||||||
					<div>
 | 
										<div>
 | 
				
			||||||
						<div>
 | 
											<div class="thumbnail" :style="thumbnail(file)"></div>
 | 
				
			||||||
							<span style="margin-right:16px;">{{ file.type }}</span>
 | 
					 | 
				
			||||||
							<span>{{ file.datasize | bytes }}</span>
 | 
					 | 
				
			||||||
						</div>
 | 
					 | 
				
			||||||
						<div><mk-time :time="file.createdAt" mode="detail"/></div>
 | 
					 | 
				
			||||||
					</div>
 | 
										</div>
 | 
				
			||||||
 | 
										<div>
 | 
				
			||||||
 | 
											<header>
 | 
				
			||||||
 | 
												<b>{{ file.name }}</b>
 | 
				
			||||||
 | 
												<span class="username">@{{ file.user | acct }}</span>
 | 
				
			||||||
 | 
											</header>
 | 
				
			||||||
 | 
											<div>
 | 
				
			||||||
 | 
												<div>
 | 
				
			||||||
 | 
													<span style="margin-right:16px;">{{ file.type }}</span>
 | 
				
			||||||
 | 
													<span>{{ file.datasize | bytes }}</span>
 | 
				
			||||||
 | 
												</div>
 | 
				
			||||||
 | 
												<div><mk-time :time="file.createdAt" mode="detail"/></div>
 | 
				
			||||||
 | 
											</div>
 | 
				
			||||||
 | 
										</div>
 | 
				
			||||||
 | 
									</div>
 | 
				
			||||||
 | 
									<div v-show="file._open">
 | 
				
			||||||
 | 
										<ui-button @click="del(file)"><fa :icon="faTrashAlt"/> {{ $t('delete') }}</ui-button>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
			</div>
 | 
								</div>
 | 
				
			||||||
			<ui-button v-if="existMore" @click="fetch">{{ $t('@.load-more') }}</ui-button>
 | 
								<ui-button v-if="existMore" @click="fetch">{{ $t('@.load-more') }}</ui-button>
 | 
				
			||||||
| 
						 | 
					@ -46,6 +51,7 @@
 | 
				
			||||||
import Vue from 'vue';
 | 
					import Vue from 'vue';
 | 
				
			||||||
import i18n from '../../i18n';
 | 
					import i18n from '../../i18n';
 | 
				
			||||||
import { faCloud } from '@fortawesome/free-solid-svg-icons';
 | 
					import { faCloud } from '@fortawesome/free-solid-svg-icons';
 | 
				
			||||||
 | 
					import { faTrashAlt } from '@fortawesome/free-regular-svg-icons';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default Vue.extend({
 | 
					export default Vue.extend({
 | 
				
			||||||
	i18n: i18n('admin/views/drive.vue'),
 | 
						i18n: i18n('admin/views/drive.vue'),
 | 
				
			||||||
| 
						 | 
					@ -58,7 +64,7 @@ export default Vue.extend({
 | 
				
			||||||
			offset: 0,
 | 
								offset: 0,
 | 
				
			||||||
			files: [],
 | 
								files: [],
 | 
				
			||||||
			existMore: false,
 | 
								existMore: false,
 | 
				
			||||||
			faCloud
 | 
								faCloud, faTrashAlt
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,6 +100,9 @@ export default Vue.extend({
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					this.existMore = false;
 | 
										this.existMore = false;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									for (const x of files) {
 | 
				
			||||||
 | 
										x._open = false;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				this.files = this.files.concat(files);
 | 
									this.files = this.files.concat(files);
 | 
				
			||||||
				this.offset += this.limit;
 | 
									this.offset += this.limit;
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
| 
						 | 
					@ -104,6 +113,23 @@ export default Vue.extend({
 | 
				
			||||||
				'background-color': file.properties.avgColor && file.properties.avgColor.length == 3 ? `rgb(${file.properties.avgColor.join(',')})` : 'transparent',
 | 
									'background-color': file.properties.avgColor && file.properties.avgColor.length == 3 ? `rgb(${file.properties.avgColor.join(',')})` : 'transparent',
 | 
				
			||||||
				'background-image': `url(${file.thumbnailUrl})`
 | 
									'background-image': `url(${file.thumbnailUrl})`
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							async del(file: any) {
 | 
				
			||||||
 | 
								const process = async () => {
 | 
				
			||||||
 | 
									await this.$root.api('drive/files/delete', { fileId: file.id });
 | 
				
			||||||
 | 
									this.$root.dialog({
 | 
				
			||||||
 | 
										type: 'success',
 | 
				
			||||||
 | 
										text: this.$t('deleted')
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								await process().catch(e => {
 | 
				
			||||||
 | 
									this.$root.dialog({
 | 
				
			||||||
 | 
										type: 'error',
 | 
				
			||||||
 | 
										text: e.toString()
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					@ -115,30 +141,33 @@ export default Vue.extend({
 | 
				
			||||||
		padding 16px
 | 
							padding 16px
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.kidvdlkg
 | 
						.kidvdlkg
 | 
				
			||||||
		display flex
 | 
					 | 
				
			||||||
		padding 16px 0
 | 
							padding 16px 0
 | 
				
			||||||
		border-top solid 1px var(--faceDivider)
 | 
							border-top solid 1px var(--faceDivider)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		> div:first-child
 | 
							> div:first-child
 | 
				
			||||||
			> .thumbnail
 | 
								display flex
 | 
				
			||||||
				display block
 | 
								cursor pointer
 | 
				
			||||||
				width 64px
 | 
					 | 
				
			||||||
				height 64px
 | 
					 | 
				
			||||||
				background-size cover
 | 
					 | 
				
			||||||
				background-position center center
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		> div:last-child
 | 
								> div:nth-child(1)
 | 
				
			||||||
			flex 1
 | 
									> .thumbnail
 | 
				
			||||||
			padding-left 16px
 | 
										display block
 | 
				
			||||||
 | 
										width 64px
 | 
				
			||||||
 | 
										height 64px
 | 
				
			||||||
 | 
										background-size cover
 | 
				
			||||||
 | 
										background-position center center
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			@media (max-width 500px)
 | 
								> div:nth-child(2)
 | 
				
			||||||
				font-size 14px
 | 
									flex 1
 | 
				
			||||||
 | 
									padding-left 16px
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			> header
 | 
									@media (max-width 500px)
 | 
				
			||||||
				word-break break-word
 | 
										font-size 14px
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				> .username
 | 
									> header
 | 
				
			||||||
					margin-left 8px
 | 
										word-break break-word
 | 
				
			||||||
					opacity 0.7
 | 
					
 | 
				
			||||||
 | 
										> .username
 | 
				
			||||||
 | 
											margin-left 8px
 | 
				
			||||||
 | 
											opacity 0.7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</style>
 | 
					</style>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,10 +63,12 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const q =
 | 
						const q = {
 | 
				
			||||||
		ps.origin == 'local' ? { host: null } :
 | 
							'metadata.deletedAt': { $exists: false },
 | 
				
			||||||
		ps.origin == 'remote' ? { host: { $ne: null } } :
 | 
						} as any;
 | 
				
			||||||
		{};
 | 
					
 | 
				
			||||||
 | 
						if (ps.origin == 'local') q['metadata._user.host'] = null;
 | 
				
			||||||
 | 
						if (ps.origin == 'remote') q['metadata._user.host'] = { $ne: null };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const files = await File
 | 
						const files = await File
 | 
				
			||||||
		.find(q, {
 | 
							.find(q, {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,14 +32,17 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Fetch file
 | 
						// Fetch file
 | 
				
			||||||
	const file = await DriveFile
 | 
						const file = await DriveFile
 | 
				
			||||||
		.findOne({
 | 
							.findOne({
 | 
				
			||||||
			_id: ps.fileId,
 | 
								_id: ps.fileId
 | 
				
			||||||
			'metadata.userId': user._id
 | 
					 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (file === null) {
 | 
						if (file === null) {
 | 
				
			||||||
		return rej('file-not-found');
 | 
							return rej('file-not-found');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!user.isAdmin && !user.isModerator && !file.metadata.userId.equals(user._id)) {
 | 
				
			||||||
 | 
							return rej('access denied');
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Delete
 | 
						// Delete
 | 
				
			||||||
	await del(file);
 | 
						await del(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue