feat(actions): rtorrent add folder rename toggle (#756)

* feat(actions): rtorrent add folder rename toggle

* refactor: use content layout
This commit is contained in:
metonym 2023-03-19 13:25:53 -07:00 committed by GitHub
parent 4449df66aa
commit 9fed6b3735
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 9 deletions

View file

@ -41,11 +41,18 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
}) })
} }
if action.SavePath != "" { if action.SavePath != "" {
if action.ContentLayout == domain.ActionContentLayoutSubfolderNone {
args = append(args, &rtorrent.FieldValue{
Field: "d.directory_base",
Value: action.SavePath,
})
} else {
args = append(args, &rtorrent.FieldValue{ args = append(args, &rtorrent.FieldValue{
Field: rtorrent.DDirectory, Field: rtorrent.DDirectory,
Value: action.SavePath, Value: action.SavePath,
}) })
} }
}
if err := rt.Add(release.MagnetURI, args...); err != nil { if err := rt.Add(release.MagnetURI, args...); err != nil {
return nil, errors.Wrap(err, "could not add torrent from magnet: %s", release.MagnetURI) return nil, errors.Wrap(err, "could not add torrent from magnet: %s", release.MagnetURI)
@ -77,11 +84,18 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
}) })
} }
if action.SavePath != "" { if action.SavePath != "" {
if action.ContentLayout == domain.ActionContentLayoutSubfolderNone {
args = append(args, &rtorrent.FieldValue{
Field: "d.directory_base",
Value: action.SavePath,
})
} else {
args = append(args, &rtorrent.FieldValue{ args = append(args, &rtorrent.FieldValue{
Field: rtorrent.DDirectory, Field: rtorrent.DDirectory,
Value: action.SavePath, Value: action.SavePath,
}) })
} }
}
if err := rt.AddTorrent(tmpFile, args...); err != nil { if err := rt.AddTorrent(tmpFile, args...); err != nil {
return nil, errors.Wrap(err, "could not add torrent file: %s", release.TorrentTmpFile) return nil, errors.Wrap(err, "could not add torrent file: %s", release.TorrentTmpFile)

View file

@ -343,6 +343,11 @@ export const ActionContentLayoutOptions: SelectGenericOption<ActionContentLayout
{ label: "Don't create subfolder", description: "Don't create subfolder", value: "SUBFOLDER_NONE" } { label: "Don't create subfolder", description: "Don't create subfolder", value: "SUBFOLDER_NONE" }
]; ];
export const ActionRtorrentRenameOptions: SelectGenericOption<ActionContentLayout>[] = [
{ label: "No", description: "No", value: "ORIGINAL" },
{ label: "Yes", description: "Yes", value: "SUBFOLDER_NONE" }
];
export interface OptionBasic { export interface OptionBasic {
label: string; label: string;
value: string; value: string;

View file

@ -1,6 +1,6 @@
import { AlertWarning } from "../../components/alerts"; import { AlertWarning } from "../../components/alerts";
import { DownloadClientSelect, NumberField, Select, SwitchGroup, TextField } from "../../components/inputs"; import { DownloadClientSelect, NumberField, Select, SwitchGroup, TextField } from "../../components/inputs";
import { ActionContentLayoutOptions, ActionTypeNameMap, ActionTypeOptions } from "../../domain/constants"; import { ActionContentLayoutOptions, ActionRtorrentRenameOptions, ActionTypeNameMap, ActionTypeOptions } from "../../domain/constants";
import React, { Fragment, useRef } from "react"; import React, { Fragment, useRef } from "react";
import { useQuery } from "react-query"; import { useQuery } from "react-query";
import { APIClient } from "../../api/APIClient"; import { APIClient } from "../../api/APIClient";
@ -359,6 +359,16 @@ const TypeForm = ({ action, idx, clients }: TypeFormProps) => {
placeholder="eg. /full/path/to/download_folder" placeholder="eg. /full/path/to/download_folder"
/> />
</div> </div>
<div className="col-span-12 sm:col-span-6">
<div className="col-span-6">
<Select
name={`actions.${idx}.content_layout`}
label="Don't add torrent's name to path"
optionDefaultText="No"
options={ActionRtorrentRenameOptions}
/>
</div>
</div>
</div> </div>
</div> </div>
); );