mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
@@ -20,6 +20,7 @@ import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.util.*
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
class ImageDownloadRunnable(
|
||||
@@ -43,10 +44,8 @@ class ImageDownloadRunnable(
|
||||
image.status = Status.DOWNLOADING
|
||||
image.downloaded = 0
|
||||
dataTransaction.updateImage(image)
|
||||
val downloadDirectory: String
|
||||
synchronized(image.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId).orElseThrow()
|
||||
downloadDirectory = post.downloadDirectory
|
||||
if (post.status != Status.DOWNLOADING) {
|
||||
post.status = Status.DOWNLOADING
|
||||
dataTransaction.updatePost(post)
|
||||
@@ -61,13 +60,14 @@ class ImageDownloadRunnable(
|
||||
log.debug(
|
||||
"Sanitizing image name from ${downloadedImage.name} to $sanitizedFileName"
|
||||
)
|
||||
checkImageTypeAndRename(
|
||||
downloadDirectory, downloadedImage, image.index
|
||||
)
|
||||
synchronized(image.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId).orElseThrow()
|
||||
val downloadDirectory = Path(post.downloadDirectory, post.folderName).pathString
|
||||
checkImageTypeAndRename(
|
||||
downloadDirectory, downloadedImage, image.index
|
||||
)
|
||||
if (image.downloaded == image.size && image.size > 0) {
|
||||
image.status = Status.FINISHED
|
||||
val post = dataTransaction.findPostById(context.postId).orElseThrow()
|
||||
post.done += 1
|
||||
post.downloaded += image.size
|
||||
dataTransaction.updatePost(post)
|
||||
@@ -102,9 +102,7 @@ class ImageDownloadRunnable(
|
||||
if (existingExtension.isBlank()) "${downloadedImage.name}.$extension" else downloadedImage.name
|
||||
try {
|
||||
val downloadDestinationFolder = Path.of(downloadDirectory)
|
||||
synchronized(downloadDestinationFolder.pathString.intern()) {
|
||||
Files.createDirectories(downloadDestinationFolder)
|
||||
}
|
||||
Files.createDirectories(downloadDestinationFolder)
|
||||
val image = downloadDestinationFolder.resolve(
|
||||
"${
|
||||
if (settings.downloadSettings.forceOrder) String.format(
|
||||
|
||||
@@ -3,6 +3,8 @@ package me.vripper.entities
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import me.vripper.entities.domain.Status
|
||||
import java.time.LocalDateTime
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
data class Post(
|
||||
val id: Long = -1,
|
||||
@@ -17,12 +19,18 @@ data class Post(
|
||||
val hosts: Set<String>,
|
||||
val downloadDirectory: String,
|
||||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") val addedOn: LocalDateTime = LocalDateTime.now(),
|
||||
var folderName: String,
|
||||
var status: Status = Status.STOPPED,
|
||||
var done: Int = 0,
|
||||
var rank: Int = Int.MAX_VALUE,
|
||||
var size: Long = -1,
|
||||
var downloaded: Long = 0,
|
||||
) {
|
||||
|
||||
fun getDownloadFolder(): String {
|
||||
return Path(downloadDirectory, folderName).pathString
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
+5
@@ -23,6 +23,7 @@ class PostDownloadStateRepositoryImpl :
|
||||
this[PostTable.rank] = post.rank
|
||||
this[PostTable.hosts] = post.hosts.joinToString(delimiter)
|
||||
this[PostTable.outputPath] = post.downloadDirectory
|
||||
this[PostTable.folderName] = post.folderName
|
||||
this[PostTable.postId] = post.postId
|
||||
this[PostTable.threadId] = post.threadId
|
||||
this[PostTable.postTitle] = post.postTitle
|
||||
@@ -90,6 +91,7 @@ class PostDownloadStateRepositoryImpl :
|
||||
it[rank] = post.rank
|
||||
it[size] = post.size
|
||||
it[downloaded] = post.downloaded
|
||||
it[folderName] = post.folderName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +104,7 @@ class PostDownloadStateRepositoryImpl :
|
||||
this[PostTable.rank] = post.rank
|
||||
this[PostTable.hosts] = post.hosts.joinToString(delimiter)
|
||||
this[PostTable.outputPath] = post.downloadDirectory
|
||||
this[PostTable.folderName] = post.folderName
|
||||
this[PostTable.postId] = post.postId
|
||||
this[PostTable.threadId] = post.threadId
|
||||
this[PostTable.postTitle] = post.postTitle
|
||||
@@ -171,6 +174,7 @@ class PostDownloadStateRepositoryImpl :
|
||||
val hosts =
|
||||
resultRow[PostTable.hosts].split(delimiter).dropLastWhile { it.isEmpty() }.toSet()
|
||||
val downloadDirectory = resultRow[PostTable.outputPath]
|
||||
val folderName = resultRow[PostTable.folderName]
|
||||
val addedOn = resultRow[PostTable.addedAt]
|
||||
val rank = resultRow[PostTable.rank]
|
||||
val size = resultRow[PostTable.size]
|
||||
@@ -188,6 +192,7 @@ class PostDownloadStateRepositoryImpl :
|
||||
hosts,
|
||||
downloadDirectory,
|
||||
addedOn,
|
||||
folderName,
|
||||
status,
|
||||
done,
|
||||
rank,
|
||||
|
||||
@@ -8,9 +8,12 @@ import me.vripper.services.*
|
||||
import me.vripper.tasks.AddPostRunnable
|
||||
import me.vripper.tasks.ThreadLookupRunnable
|
||||
import me.vripper.utilities.GLOBAL_EXECUTOR
|
||||
import me.vripper.utilities.PathUtils
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
|
||||
class AppEndpointService(
|
||||
private val downloadService: DownloadService,
|
||||
@@ -65,7 +68,7 @@ class AppEndpointService(
|
||||
|
||||
@Synchronized
|
||||
fun restartAll(posIds: List<Long> = listOf()) {
|
||||
downloadService.restartAll(posIds.map { dataTransaction.findPostsByPostId(it) }.filter { it.isPresent }
|
||||
downloadService.restartAll(posIds.map { dataTransaction.findPostByPostId(it) }.filter { it.isPresent }
|
||||
.map { it.get() })
|
||||
}
|
||||
|
||||
@@ -139,6 +142,19 @@ class AppEndpointService(
|
||||
|
||||
fun logClear() {
|
||||
dataTransaction.deleteAllLogs()
|
||||
}
|
||||
|
||||
fun rename(postId: Long, name: String) {
|
||||
CompletableFuture.runAsync({
|
||||
synchronized(postId.toString().intern()) {
|
||||
dataTransaction.findPostByPostId(postId).ifPresent { post ->
|
||||
if (Path(post.downloadDirectory, post.folderName).exists()) {
|
||||
PathUtils.rename(post.downloadDirectory, post.folderName, name)
|
||||
}
|
||||
post.folderName = name
|
||||
dataTransaction.updatePost(post)
|
||||
}
|
||||
}
|
||||
}, GLOBAL_EXECUTOR)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import me.vripper.model.ErrorCount
|
||||
import me.vripper.model.PostItem
|
||||
import me.vripper.repositories.*
|
||||
import me.vripper.utilities.PathUtils
|
||||
import me.vripper.utilities.PathUtils.sanitize
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import java.util.*
|
||||
import kotlin.io.path.pathString
|
||||
@@ -75,10 +76,11 @@ class DataTransaction(
|
||||
downloadDirectory = PathUtils.calculateDownloadPath(
|
||||
postItem.forum,
|
||||
postItem.threadTitle,
|
||||
postItem.title,
|
||||
postItem.postId,
|
||||
settingsService.settings
|
||||
).pathString
|
||||
).pathString,
|
||||
folderName = if (settingsService.settings.downloadSettings.appendPostId) "${sanitize(postItem.title)}_${postItem.postId}" else sanitize(
|
||||
postItem.title
|
||||
)
|
||||
)
|
||||
val images = postItem.imageItemList.mapIndexed { index, imageItem ->
|
||||
Image(
|
||||
@@ -115,7 +117,7 @@ class DataTransaction(
|
||||
}
|
||||
|
||||
fun finishPost(postId: Long, automatic: Boolean = false) {
|
||||
val post = findPostsByPostId(postId).orElseThrow()
|
||||
val post = findPostByPostId(postId).orElseThrow()
|
||||
val imagesInErrorStatus = findByPostIdAndIsError(post.postId)
|
||||
if (imagesInErrorStatus.isNotEmpty()) {
|
||||
post.status = Status.ERROR
|
||||
@@ -239,7 +241,7 @@ class DataTransaction(
|
||||
return transaction { imageRepository.countError() }
|
||||
}
|
||||
|
||||
fun findPostsByPostId(postId: Long): Optional<Post> {
|
||||
fun findPostByPostId(postId: Long): Optional<Post> {
|
||||
return transaction { postDownloadStateRepository.findByPostId(postId) }
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ object PostTable : LongIdTable(name = "POST", columnName = "ID") {
|
||||
val done = integer("DONE")
|
||||
val hosts = varchar("HOSTS", 255)
|
||||
val outputPath = varchar("OUTPUT_PATH", 260)
|
||||
val folderName = varchar("FOLDER_NAME", 260)
|
||||
val postId = long("POST_ID")
|
||||
val status = varchar("STATUS", 15)
|
||||
val threadId = long("THREAD_ID")
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import me.vripper.exception.RenameException
|
||||
import me.vripper.model.Settings
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
import kotlin.io.path.Path
|
||||
|
||||
|
||||
object PathUtils {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
@@ -9,7 +15,7 @@ object PathUtils {
|
||||
|
||||
|
||||
fun calculateDownloadPath(
|
||||
forum: String, threadTitle: String, postTitle: String, postId: Long, settings: Settings
|
||||
forum: String, threadTitle: String, settings: Settings
|
||||
): Path {
|
||||
var downloadDirectory = if (settings.downloadSettings.forumSubDirectory) Path.of(
|
||||
settings.downloadSettings.downloadPath, sanitize(forum)
|
||||
@@ -18,14 +24,29 @@ object PathUtils {
|
||||
)
|
||||
downloadDirectory =
|
||||
if (settings.downloadSettings.threadSubLocation) downloadDirectory.resolve(threadTitle) else downloadDirectory
|
||||
downloadDirectory = downloadDirectory.resolve(
|
||||
if (settings.downloadSettings.appendPostId) "${sanitize(postTitle)}_${postId}" else sanitize(
|
||||
postTitle
|
||||
)
|
||||
)
|
||||
return downloadDirectory
|
||||
}
|
||||
|
||||
@Throws(RenameException::class)
|
||||
fun rename(downloadDirectory: String, oldFolder: String, newFolder: String) {
|
||||
val currentDownloadDirectory = Path(downloadDirectory, oldFolder)
|
||||
val newDownloadDirectory = Path(downloadDirectory, sanitize(newFolder))
|
||||
try {
|
||||
Files.move(
|
||||
currentDownloadDirectory,
|
||||
newDownloadDirectory,
|
||||
StandardCopyOption.ATOMIC_MOVE
|
||||
)
|
||||
} catch (e: IOException) {
|
||||
throw RenameException(
|
||||
String.format(
|
||||
"Failed to move files from %s to %s", currentDownloadDirectory, newDownloadDirectory
|
||||
),
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will sanitize the image name and remove extension
|
||||
*
|
||||
|
||||
@@ -145,4 +145,9 @@
|
||||
<column name="THREAD_ID"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet id="0006" author="vripper">
|
||||
<addColumn tableName="POST">
|
||||
<column name="FOLDER_NAME" type="VARCHAR(260)" afterColumn="OUTPUT_PATH" defaultValue=""/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
||||
@@ -2,7 +2,6 @@ package me.vripper.gui.controller
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.entities.Image
|
||||
import me.vripper.entities.Post
|
||||
import me.vripper.gui.model.PostModel
|
||||
import me.vripper.services.AppEndpointService
|
||||
import me.vripper.services.DataTransaction
|
||||
@@ -58,25 +57,26 @@ class PostController : Controller() {
|
||||
}
|
||||
|
||||
fun findAllPosts(): Deferred<List<PostModel>> {
|
||||
return coroutineScope.async { dataTransaction.findAllPosts().map(::mapper) }
|
||||
return coroutineScope.async { dataTransaction.findAllPosts().map { it.id }.map(::mapper) }
|
||||
}
|
||||
|
||||
fun mapper(it: Post): PostModel {
|
||||
val updated = dataTransaction.findPostById(it.id).orElseThrow()
|
||||
fun mapper(id: Long): PostModel {
|
||||
val post = dataTransaction.findPostById(id).orElseThrow()
|
||||
return PostModel(
|
||||
updated.postId,
|
||||
updated.postTitle,
|
||||
progress(updated.total, updated.done),
|
||||
updated.status.name,
|
||||
updated.url,
|
||||
updated.done,
|
||||
updated.total,
|
||||
updated.hosts.joinToString(separator = ", "),
|
||||
updated.addedOn.format(dateTimeFormatter),
|
||||
updated.rank + 1,
|
||||
updated.downloadDirectory,
|
||||
progressCount(updated.total, updated.done, updated.downloaded),
|
||||
dataTransaction.findImagesByPostId(updated.postId).map(Image::thumbUrl).take(4)
|
||||
post.postId,
|
||||
post.postTitle,
|
||||
progress(post.total, post.done),
|
||||
post.status.name,
|
||||
post.url,
|
||||
post.done,
|
||||
post.total,
|
||||
post.hosts.joinToString(separator = ", "),
|
||||
post.addedOn.format(dateTimeFormatter),
|
||||
post.rank + 1,
|
||||
post.getDownloadFolder(),
|
||||
post.folderName,
|
||||
progressCount(post.total, post.done, post.downloaded),
|
||||
dataTransaction.findImagesByPostId(post.postId).map(Image::thumbUrl).take(4)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -87,4 +87,8 @@ class PostController : Controller() {
|
||||
fun progress(total: Int, done: Int): Double {
|
||||
return if (done == 0 && total == 0) 0.0 else (done.toDouble() / total)
|
||||
}
|
||||
|
||||
fun rename(postId: Long, value: String) {
|
||||
appEndpointService.rename(postId, value)
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class PostModel(
|
||||
addedOn: String,
|
||||
order: Int,
|
||||
path: String,
|
||||
folderName: String,
|
||||
progressCount: String,
|
||||
previewList: List<String>
|
||||
) {
|
||||
@@ -55,6 +56,9 @@ class PostModel(
|
||||
val pathProperty = SimpleStringProperty(path)
|
||||
var path: String by pathProperty
|
||||
|
||||
val folderNameProperty = SimpleStringProperty(folderName)
|
||||
var folderName: String by folderNameProperty
|
||||
|
||||
val progressCountProperty = SimpleStringProperty(progressCount)
|
||||
var progressCount: String by progressCountProperty
|
||||
|
||||
|
||||
@@ -98,6 +98,25 @@ class DownloadActionsView : View() {
|
||||
postsTableView.stopSelected()
|
||||
}
|
||||
}
|
||||
button("Rename") {
|
||||
setPrefSize(32.0, 32.0)
|
||||
imageview("edit.png") {
|
||||
fitWidth = 32.0
|
||||
fitHeight = 32.0
|
||||
}
|
||||
addClass(Styles.actionBarButton)
|
||||
contentDisplay = ContentDisplay.GRAPHIC_ONLY
|
||||
tooltip("Rename selected [Ctrl+R]")
|
||||
shortcut(KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN))
|
||||
enableWhen(
|
||||
postsTableView.tableView.selectionModel.selectedItems.sizeProperty.greaterThan(
|
||||
0
|
||||
)
|
||||
)
|
||||
action {
|
||||
postsTableView.renameSelected()
|
||||
}
|
||||
}
|
||||
button("Delete") {
|
||||
setPrefSize(32.0, 32.0)
|
||||
imageview("trash.png") {
|
||||
|
||||
@@ -21,6 +21,7 @@ import me.vripper.gui.clipboard.ClipboardService
|
||||
import me.vripper.gui.controller.PostController
|
||||
import me.vripper.gui.model.PostModel
|
||||
import me.vripper.gui.view.*
|
||||
import me.vripper.gui.view.popup.RenameView
|
||||
import tornadofx.*
|
||||
|
||||
class PostsTableView : View() {
|
||||
@@ -57,7 +58,7 @@ class PostsTableView : View() {
|
||||
}
|
||||
|
||||
eventBus.events.ofType(PostCreateEvent::class.java).subscribe { postEvents ->
|
||||
val add = postEvents.posts.map { postController.mapper(it) }
|
||||
val add = postEvents.posts.map { postController.mapper(it.id) }
|
||||
runLater {
|
||||
tableView.items.addAll(add)
|
||||
}
|
||||
@@ -77,6 +78,8 @@ class PostsTableView : View() {
|
||||
postModel.progress = postController.progress(
|
||||
post.total, post.done
|
||||
)
|
||||
postModel.path = post.getDownloadFolder()
|
||||
postModel.folderName = post.folderName
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +124,16 @@ class PostsTableView : View() {
|
||||
}
|
||||
}
|
||||
|
||||
val renameItem = MenuItem("Rename").apply {
|
||||
setOnAction {
|
||||
rename(tableRow.item)
|
||||
}
|
||||
graphic = ImageView("edit.png").apply {
|
||||
fitWidth = 18.0
|
||||
fitHeight = 18.0
|
||||
}
|
||||
}
|
||||
|
||||
val deleteItem = MenuItem("Delete").apply {
|
||||
setOnAction {
|
||||
deleteSelected()
|
||||
@@ -163,7 +176,7 @@ class PostsTableView : View() {
|
||||
|
||||
val contextMenu = ContextMenu()
|
||||
contextMenu.items.addAll(
|
||||
startItem, stopItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem, urlItem
|
||||
startItem, stopItem, renameItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem, urlItem
|
||||
)
|
||||
tableRow.contextMenuProperty()
|
||||
.bind(tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu })
|
||||
@@ -284,6 +297,20 @@ class PostsTableView : View() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun rename(post: PostModel) {
|
||||
find<RenameView>(mapOf(RenameView::postId to post.postId, RenameView::name to post.folderName)).openModal()
|
||||
?.apply {
|
||||
minWidth = 300.0
|
||||
}
|
||||
}
|
||||
|
||||
fun renameSelected() {
|
||||
val selectedItem = tableView.selectionModel.selectedItem
|
||||
if (selectedItem != null) {
|
||||
rename(selectedItem)
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteSelected() {
|
||||
val postIdList = tableView.selectionModel.selectedItems.map { it.postId }
|
||||
confirm(
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
(startSelected)="onStartSelected()"
|
||||
(stopSelected)="onStopSelected()"
|
||||
(deleteSelected)="onDeleteSelected()"
|
||||
(renameSelected)='onRenameSelected()'
|
||||
(clearDownload)="onClearDownloads()"
|
||||
(clearLogs)="onClearLogs()"
|
||||
(clearThreads)="onClearThreads()"></app-toolbar>
|
||||
@@ -24,7 +25,8 @@
|
||||
</mat-icon>
|
||||
</ng-template>
|
||||
<app-download-table
|
||||
(selectedChange)="onPostsSelectionChange($event)"
|
||||
(selectedPostsChange)='onPostsSelectionChange($event)'
|
||||
(selectedPostChange)='onPostSelectionChange($event)'
|
||||
(rowCountChange)="downloadCount.set($event)"></app-download-table>
|
||||
</mat-tab>
|
||||
<mat-tab>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, computed, signal } from '@angular/core';
|
||||
import { Component, computed, signal, WritableSignal } from '@angular/core';
|
||||
import { ToolbarComponent } from './toolbar/toolbar.component';
|
||||
import { CommonModule, NgIf } from '@angular/common';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
@@ -20,9 +20,14 @@ import {
|
||||
ConfirmComponent,
|
||||
ConfirmDialogData,
|
||||
} from './confirm/confirm.component';
|
||||
import { Subject } from 'rxjs';
|
||||
import { EMPTY, mergeMap, Subject } from 'rxjs';
|
||||
import { RxStompState } from '@stomp/rx-stomp';
|
||||
import { StatusBarComponent } from './status-bar/status-bar.component';
|
||||
import {
|
||||
RenameDialogComponent,
|
||||
RenameDialogData,
|
||||
RenameDialogResult,
|
||||
} from './rename-dialog/rename-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -49,6 +54,7 @@ export class AppComponent {
|
||||
logCount = signal(0);
|
||||
tabIndex = signal(0);
|
||||
|
||||
selectedPost: WritableSignal<Post | null> = signal(null);
|
||||
selectedPosts = signal([] as Post[]);
|
||||
noPostSelected = computed(() => this.selectedPosts().length === 0);
|
||||
loading = computed(
|
||||
@@ -71,6 +77,10 @@ export class AppComponent {
|
||||
this.selectedPosts.set(selectedPosts);
|
||||
};
|
||||
|
||||
onPostSelectionChange = (selectedPost: Post) => {
|
||||
this.selectedPost.set(selectedPost);
|
||||
};
|
||||
|
||||
onStartSelected = () => {
|
||||
if (this.selectedPosts().length > 0) {
|
||||
this.applicationEndpoint.startPosts(this.selectedPosts()).subscribe();
|
||||
@@ -122,6 +132,39 @@ export class AppComponent {
|
||||
});
|
||||
};
|
||||
|
||||
onRenameSelected = () => {
|
||||
if (this.selectedPost() == null) {
|
||||
return;
|
||||
}
|
||||
const post = this.selectedPost();
|
||||
if (post?.postId == null || post?.folderName == null) {
|
||||
return;
|
||||
}
|
||||
const dialog: MatDialogRef<RenameDialogComponent, RenameDialogResult> =
|
||||
this.dialog.open<
|
||||
RenameDialogComponent,
|
||||
RenameDialogData,
|
||||
RenameDialogResult
|
||||
>(RenameDialogComponent, {
|
||||
data: {
|
||||
postId: post.postId,
|
||||
name: post.folderName,
|
||||
},
|
||||
});
|
||||
dialog
|
||||
.afterClosed()
|
||||
.pipe(
|
||||
mergeMap(result => {
|
||||
if (result) {
|
||||
return this.applicationEndpoint.renamePost(result);
|
||||
} else {
|
||||
return EMPTY;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
};
|
||||
|
||||
onClearDownloads = () => {
|
||||
const confirmDialog: MatDialogRef<ConfirmComponent, ConfirmDialogData> =
|
||||
this.dialog.open<ConfirmComponent, ConfirmDialogData>(ConfirmComponent, {
|
||||
|
||||
@@ -6,6 +6,7 @@ export class PostRow extends Post {
|
||||
public statusIcon: WritableSignal<string>;
|
||||
public progress: WritableSignal<number>;
|
||||
public total2: WritableSignal<string>;
|
||||
public path: WritableSignal<string>;
|
||||
|
||||
constructor(
|
||||
postId: number,
|
||||
@@ -18,6 +19,8 @@ export class PostRow extends Post {
|
||||
addedOn: string,
|
||||
rank: number,
|
||||
downloadDirectory: string,
|
||||
folderName: string,
|
||||
downloadFolder: string,
|
||||
downloaded: number
|
||||
) {
|
||||
super(
|
||||
@@ -31,10 +34,13 @@ export class PostRow extends Post {
|
||||
addedOn,
|
||||
rank,
|
||||
downloadDirectory,
|
||||
folderName,
|
||||
downloadFolder,
|
||||
downloaded
|
||||
);
|
||||
this.statusIcon = signal(statusIcon(status));
|
||||
this.progress = signal(progress(done, total));
|
||||
this.total2 = signal(totalFormatter(done, total, downloaded));
|
||||
this.path = signal(downloadFolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ export class Post {
|
||||
public addedOn: string,
|
||||
public rank: number,
|
||||
public downloadDirectory: string,
|
||||
public folderName: string,
|
||||
public downloadFolder: string,
|
||||
public downloaded: number
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@
|
||||
<th *matHeaderCellDef mat-header-cell>Path</th>
|
||||
<td
|
||||
*matCellDef="let element"
|
||||
[title]="element.downloadDirectory"
|
||||
[title]='element.path()'
|
||||
class="truncate-cell"
|
||||
mat-cell>
|
||||
{{ element.downloadDirectory }}
|
||||
{{ element.path() }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
|
||||
@@ -8,7 +8,14 @@ import {
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Post } from '../domain/post.model';
|
||||
import { BehaviorSubject, Observable, Subscription, take } from 'rxjs';
|
||||
import {
|
||||
BehaviorSubject,
|
||||
EMPTY,
|
||||
mergeMap,
|
||||
Observable,
|
||||
Subscription,
|
||||
take,
|
||||
} from 'rxjs';
|
||||
import { ApplicationEndpointService } from '../services/application-endpoint.service';
|
||||
import {
|
||||
Overlay,
|
||||
@@ -41,6 +48,11 @@ import {
|
||||
ConfirmDialogData,
|
||||
} from '../confirm/confirm.component';
|
||||
import { PostRow } from '../domain/post-row.model';
|
||||
import {
|
||||
RenameDialogComponent,
|
||||
RenameDialogData,
|
||||
RenameDialogResult,
|
||||
} from '../rename-dialog/rename-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-download-table',
|
||||
@@ -67,7 +79,9 @@ export class DownloadTableComponent {
|
||||
rowCountChange = new EventEmitter<number>();
|
||||
|
||||
@Output()
|
||||
selectedChange = new EventEmitter<Post[]>();
|
||||
selectedPostsChange = new EventEmitter<Post[]>();
|
||||
@Output()
|
||||
selectedPostChange = new EventEmitter<Post>();
|
||||
|
||||
displayedColumns: string[] = [
|
||||
'title',
|
||||
@@ -100,9 +114,10 @@ export class DownloadTableComponent {
|
||||
this.dataSource._dataStream.subscribe(v =>
|
||||
this.rowCountChange.emit(v.length)
|
||||
);
|
||||
this.selection.changed.subscribe(() =>
|
||||
this.selectedChange.emit(this.selection.selected)
|
||||
);
|
||||
this.selection.changed.subscribe(selectionChange => {
|
||||
this.selectedPostChange.emit(selectionChange.added[0]);
|
||||
this.selectedPostsChange.emit(this.selection.selected);
|
||||
});
|
||||
this.breakpointObserver
|
||||
.observe([Breakpoints.XSmall, Breakpoints.Small, Breakpoints.Medium])
|
||||
.subscribe(result => {
|
||||
@@ -214,6 +229,29 @@ export class DownloadTableComponent {
|
||||
ref.instance.onPostStop = () =>
|
||||
this.applicationEndpoint.stopPosts(this.selection.selected).subscribe();
|
||||
|
||||
ref.instance.onPostRename = () => {
|
||||
const dialog: MatDialogRef<RenameDialogComponent, RenameDialogResult> =
|
||||
this.dialog.open<
|
||||
RenameDialogComponent,
|
||||
RenameDialogData,
|
||||
RenameDialogResult
|
||||
>(RenameDialogComponent, {
|
||||
data: { postId: row.postId, name: row.folderName },
|
||||
});
|
||||
dialog
|
||||
.afterClosed()
|
||||
.pipe(
|
||||
mergeMap(result => {
|
||||
if (result) {
|
||||
return this.applicationEndpoint.renamePost(result);
|
||||
} else {
|
||||
return EMPTY;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
};
|
||||
|
||||
ref.instance.onPostDelete = () => {
|
||||
const dialog: MatDialogRef<ConfirmComponent, ConfirmDialogData> =
|
||||
this.dialog.open<ConfirmComponent, ConfirmDialogData>(
|
||||
@@ -271,6 +309,8 @@ class PostDataSource extends DataSource<PostRow> {
|
||||
e.addedOn,
|
||||
e.rank,
|
||||
e.downloadDirectory,
|
||||
e.folderName,
|
||||
e.downloadFolder,
|
||||
e.downloaded
|
||||
)
|
||||
),
|
||||
@@ -299,6 +339,7 @@ class PostDataSource extends DataSource<PostRow> {
|
||||
rowNode.statusIcon.set(statusIcon(v.status));
|
||||
rowNode.progress.set(progress(v.done, v.total));
|
||||
rowNode.total2.set(totalFormatter(v.done, v.total, v.downloaded));
|
||||
rowNode.path.set(v.downloadFolder);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
<mat-icon matListItemIcon>pause</mat-icon>
|
||||
<div matListItemTitle>Stop</div>
|
||||
</mat-list-item>
|
||||
<mat-list-item (click)='onPostRename(); close()'>
|
||||
<mat-icon matListItemIcon>edit</mat-icon>
|
||||
<div matListItemTitle>Rename</div>
|
||||
</mat-list-item>
|
||||
<mat-list-item (click)="onPostDelete(); close()">
|
||||
<mat-icon matListItemIcon>delete</mat-icon>
|
||||
<div matListItemTitle>Remove</div>
|
||||
|
||||
@@ -46,10 +46,8 @@ export class PostContextmenuComponent {
|
||||
};
|
||||
|
||||
onPostStart!: () => void;
|
||||
|
||||
onPostStop!: () => void;
|
||||
|
||||
onPostRename!: () => void;
|
||||
onPostDelete!: () => void;
|
||||
|
||||
close!: () => void;
|
||||
}
|
||||
|
||||
@@ -219,6 +219,8 @@ export class ApplicationEndpointService {
|
||||
element.addedOn,
|
||||
element.rank + 1,
|
||||
element.downloadDirectory,
|
||||
element.folderName,
|
||||
element.downloadFolder,
|
||||
element.downloaded
|
||||
);
|
||||
});
|
||||
@@ -240,6 +242,8 @@ export class ApplicationEndpointService {
|
||||
element.addedOn,
|
||||
element.rank + 1,
|
||||
element.downloadDirectory,
|
||||
element.folderName,
|
||||
element.downloadFolder,
|
||||
element.downloaded
|
||||
);
|
||||
});
|
||||
@@ -370,4 +374,8 @@ export class ApplicationEndpointService {
|
||||
clearThreads() {
|
||||
return this.httpClient.get<void>(this.baseUrl + '/api/grab/clear');
|
||||
}
|
||||
|
||||
renamePost(data: { postId: number; name: string }) {
|
||||
return this.httpClient.post<void>(this.baseUrl + '/api/post/rename', data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,13 @@
|
||||
<mat-icon>pause</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
[disabled]='disableSelected()'
|
||||
(click)='renameSelectedClick()'
|
||||
mat-icon-button
|
||||
matTooltip='Rename selected'>
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
[disabled]="disableSelected()"
|
||||
(click)="removeSelectedClick()"
|
||||
mat-icon-button
|
||||
|
||||
@@ -49,6 +49,9 @@ export class ToolbarComponent {
|
||||
@Output()
|
||||
deleteSelected = new EventEmitter<void>();
|
||||
|
||||
@Output()
|
||||
renameSelected = new EventEmitter<void>();
|
||||
|
||||
@Output()
|
||||
clearDownload = new EventEmitter<void>();
|
||||
|
||||
@@ -117,6 +120,10 @@ export class ToolbarComponent {
|
||||
this.deleteSelected.next();
|
||||
}
|
||||
|
||||
renameSelectedClick() {
|
||||
this.renameSelected.next();
|
||||
}
|
||||
|
||||
clearDownloadsClick() {
|
||||
this.clearDownload.next();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ package me.vripper.web.restendpoints
|
||||
import me.vripper.model.PostItem
|
||||
import me.vripper.model.ThreadPostId
|
||||
import me.vripper.services.AppEndpointService
|
||||
import me.vripper.web.restendpoints.domain.*
|
||||
import me.vripper.web.restendpoints.domain.RenameRequest
|
||||
import me.vripper.web.restendpoints.domain.ScanRequest
|
||||
import me.vripper.web.restendpoints.exceptions.BadRequestException
|
||||
import me.vripper.web.restendpoints.exceptions.ServerErrorException
|
||||
import org.koin.core.component.KoinComponent
|
||||
@@ -98,4 +99,10 @@ class PostRestEndpoint : KoinComponent {
|
||||
fun threadClear() {
|
||||
appEndpointService.threadClear()
|
||||
}
|
||||
|
||||
@PostMapping("/post/rename")
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
fun rename(@RequestBody renameRequest: RenameRequest) {
|
||||
appEndpointService.rename(renameRequest.postId, renameRequest.name)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user