mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Creating new /api/archive/upload which accepts a file from the SingleFile browser extension and converts it to an Archive.
This commit is contained in:
parent
01338e4d89
commit
531ec3d65e
62 changed files with 1000 additions and 562 deletions
|
|
@ -5,7 +5,6 @@ import {
|
|||
CardHeader,
|
||||
CardMeta,
|
||||
Container,
|
||||
Dropdown,
|
||||
GridColumn,
|
||||
GridRow,
|
||||
Image,
|
||||
|
|
@ -24,8 +23,8 @@ import {
|
|||
ExternalCardLink,
|
||||
FileIcon,
|
||||
findPosterPath,
|
||||
InfoHeader,
|
||||
humanFileSize,
|
||||
InfoHeader,
|
||||
isoDatetimeToAgoPopup,
|
||||
mimetypeColor,
|
||||
PageContainer,
|
||||
|
|
@ -39,7 +38,7 @@ import {
|
|||
import {deleteArchives, postDownload, tagFileGroup, untagFileGroup} from "../api";
|
||||
import {Link, Route, Routes, useNavigate, useParams} from "react-router-dom";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
import {useArchive, useDomains, useSearchArchives, useSearchDomain, useSearchOrder} from "../hooks/customHooks";
|
||||
import {useArchive, useDomains, useSearchArchives, useSearchOrder} from "../hooks/customHooks";
|
||||
import {FileCards, FileRowTagIcon, FilesView} from "./Files";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import _ from "lodash";
|
||||
|
|
@ -48,7 +47,7 @@ import {Button, Card, CardIcon, darkTheme, Header, Loader, Placeholder, Popup, S
|
|||
import {SortableTable} from "./SortableTable";
|
||||
import {taggedImageLabel, TagsSelector} from "../Tags";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {Downloaders} from "./Vars";
|
||||
import {API_ARCHIVE_UPLOAD_URI, Downloaders} from "./Vars";
|
||||
|
||||
function archiveFileLink(path, directory = false) {
|
||||
if (path) {
|
||||
|
|
@ -394,29 +393,47 @@ export function DomainsPage() {
|
|||
</>;
|
||||
}
|
||||
|
||||
export function SearchDomain() {
|
||||
// A Dropdown which allows the user to filter by Archive domains.
|
||||
const {domain, domains, setDomain} = useSearchDomain();
|
||||
function ArchiveSettingsPage() {
|
||||
const {t} = React.useContext(ThemeContext);
|
||||
|
||||
const handleChange = (e, {value}) => {
|
||||
setDomain(value);
|
||||
}
|
||||
const urlClipboardButton = <APIButton
|
||||
icon='copy'
|
||||
onClick={() => navigator.clipboard.writeText(API_ARCHIVE_UPLOAD_URI)}
|
||||
/>;
|
||||
const dataFieldNameClipboardButton = <APIButton
|
||||
icon='copy'
|
||||
onClick={() => navigator.clipboard.writeText('singlefile_contents')}
|
||||
/>;
|
||||
const urlFieldNameClipboardButton = <APIButton
|
||||
icon='copy'
|
||||
onClick={() => navigator.clipboard.writeText('url')}
|
||||
/>;
|
||||
|
||||
let domainOptions = [];
|
||||
return <PageContainer>
|
||||
<Header as='h1'>SingleFile Browser Extension</Header>
|
||||
|
||||
if (domains && domains.length > 0) {
|
||||
domainOptions = domains.map(i => {
|
||||
return {key: i['domain'], value: i['domain'], text: i['domain']}
|
||||
});
|
||||
}
|
||||
return <>
|
||||
<Dropdown selection search clearable fluid
|
||||
placeholder='Domains'
|
||||
options={domainOptions}
|
||||
onChange={handleChange}
|
||||
value={domain}
|
||||
<p {...t}>
|
||||
These are the settings necessary to configure the <a
|
||||
href="https://github.com/gildas-lormeau/SingleFile?tab=readme-ov-file#install">SingleFile Browser
|
||||
Extension</a> to automatically upload to your WROLPi.
|
||||
</p>
|
||||
|
||||
<label {...t}>Upload URL</label>
|
||||
<Input fluid
|
||||
value={API_ARCHIVE_UPLOAD_URI}
|
||||
label={urlClipboardButton}
|
||||
/>
|
||||
</>
|
||||
<label {...t}>Data Field Name</label>
|
||||
<Input fluid
|
||||
value='singlefile_contents'
|
||||
label={dataFieldNameClipboardButton}
|
||||
/>
|
||||
<label {...t}>URL Field Name</label>
|
||||
<Input fluid
|
||||
value='url'
|
||||
label={urlFieldNameClipboardButton}
|
||||
/>
|
||||
</PageContainer>
|
||||
}
|
||||
|
||||
function ArchivesPage() {
|
||||
|
|
@ -599,12 +616,14 @@ export function ArchiveRoute() {
|
|||
const links = [
|
||||
{text: 'Archives', to: '/archive', end: true},
|
||||
{text: 'Domains', to: '/archive/domains'},
|
||||
{text: 'Settings', to: '/archive/settings'},
|
||||
];
|
||||
return <PageContainer>
|
||||
<TabLinks links={links}/>
|
||||
<Routes>
|
||||
<Route path='/' element={<ArchivesPage/>}/>
|
||||
<Route path='domains' element={<DomainsPage/>}/>
|
||||
<Route path='settings' element={<ArchiveSettingsPage/>}/>
|
||||
<Route path=':archiveId' element={<ArchivePage/>}/>
|
||||
</Routes>
|
||||
</PageContainer>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import {
|
|||
Container,
|
||||
Dimmer,
|
||||
DimmerDimmable,
|
||||
GridColumn,
|
||||
GridRow,
|
||||
Icon as SIcon,
|
||||
IconGroup,
|
||||
Input,
|
||||
|
|
@ -48,6 +50,7 @@ import {FilePreviewContext} from "./FilePreview";
|
|||
import _ from "lodash";
|
||||
import {killDownloads, startDownloads} from "../api";
|
||||
import {allFrequencyOptions, NAME, semanticUIColorMap, validUrlRegex} from "./Vars";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
|
||||
export function Paginator({activePage, onPageChange, totalPages, showFirstAndLast, size = 'mini'}) {
|
||||
const handlePageChange = (e, {activePage}) => {
|
||||
|
|
@ -1960,14 +1963,22 @@ export function getDistinctColor(hexColors) {
|
|||
return hslToHex(newColor.h, newColor.s, newColor.l);
|
||||
}
|
||||
|
||||
export const DismissibleMessage = ({storageName, children}) => {
|
||||
const [dismissed, setDismissed] = useLocalStorage(storageName, false);
|
||||
|
||||
if (dismissed) {
|
||||
return <React.Fragment/>
|
||||
export const RefreshHeader = ({header, headerSize = 'h2', onRefresh, popupContents}) => {
|
||||
const refreshButton = <APIButton icon='refresh' onClick={onRefresh}/>;
|
||||
let popup;
|
||||
if (popupContents) {
|
||||
popup = <Popup
|
||||
content={popupContents}
|
||||
on='hover'
|
||||
trigger={refreshButton}
|
||||
/>;
|
||||
}
|
||||
|
||||
return <Message onDismiss={() => setDismissed(true)}>
|
||||
{children}
|
||||
</Message>
|
||||
return <Grid columns={2}>
|
||||
<GridRow>
|
||||
<GridColumn>
|
||||
<Header as={headerSize}>{header}</Header>
|
||||
</GridColumn>
|
||||
<GridColumn textAlign='right'>{popup || refreshButton}</GridColumn>
|
||||
</GridRow>
|
||||
</Grid>
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import {Grid, Header as SHeader, Image,} from "semantic-ui-react";
|
|||
import {TagsSelector} from "../Tags";
|
||||
import {Media} from "../contexts/contexts";
|
||||
import {encodeMediaPath} from "./Common";
|
||||
import {fetchFile, getFile, tagFileGroup, untagFileGroup} from "../api";
|
||||
import {getFile, tagFileGroup, untagFileGroup} from "../api";
|
||||
import {StlViewer} from "react-stl-viewer";
|
||||
import {Button, Modal, ModalActions, ModalContent, ModalHeader} from "./Theme";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
|
|
@ -200,7 +200,7 @@ export function FilePreviewProvider({children}) {
|
|||
// Get the file again with its Tags.
|
||||
const {path, primary_path} = previewFile;
|
||||
try {
|
||||
const file = await fetchFile(primary_path ?? path);
|
||||
const file = await getFile(primary_path ?? path);
|
||||
setPreviewFile(file);
|
||||
} finally {
|
||||
await handleCallbacks();
|
||||
|
|
@ -310,6 +310,7 @@ export function FilePreviewProvider({children}) {
|
|||
const lowerPath = path.toLowerCase();
|
||||
const url = getMediaPathURL(previewFile);
|
||||
const downloadURL = getDownloadPathURL(previewFile);
|
||||
|
||||
if (mimetype.startsWith('text/') && size > MAXIMUM_TEXT_SIZE) {
|
||||
// Large text files should be downloaded.
|
||||
window.open(downloadURL);
|
||||
|
|
@ -336,6 +337,14 @@ export function FilePreviewProvider({children}) {
|
|||
// No special handler for this file type, just open it.
|
||||
setModalContent(getGenericPreviewModal(previewFile), url, downloadURL, path, taggable);
|
||||
}
|
||||
|
||||
// Fetch the file so `FileGroup.viewed` is set.
|
||||
try {
|
||||
getFile(path);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error('Failed to get file to set FileGroup.viewed');
|
||||
}
|
||||
}
|
||||
}, [previewFile]);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export const FILES_MEDIA_URI = `https://${window.location.hostname}:${port}/medi
|
|||
export const MAP_VIEWER_URI = `https://${window.location.hostname}:8084`;
|
||||
export const ZIM_VIEWER_URI = `https://${window.location.hostname}:8085`;
|
||||
export const HELP_VIEWER_URI = `https://${window.location.hostname}:8086`;
|
||||
export const API_ARCHIVE_UPLOAD_URI = `http://${window.location.hostname}:8081/api/archive/upload`;
|
||||
|
||||
export let defaultFileOrder = '-published_datetime'; // Most recently published files first.
|
||||
export let defaultSearchOrder = 'rank'; // Most relevant files first.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import {
|
|||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Container from "semantic-ui-react/dist/commonjs/elements/Container";
|
||||
import {VideoPlaceholder} from "./Placeholder";
|
||||
import {useChannel} from "../hooks/customHooks";
|
||||
import {useChannel, useVideoCaptions, useVideoExtras} from "../hooks/customHooks";
|
||||
import {ThemeContext} from "../contexts/contexts";
|
||||
import {Button, darkTheme, Header, Icon, Segment, Tab, TabPane} from "./Theme";
|
||||
import {VideoCard} from "./Videos";
|
||||
|
|
@ -192,6 +192,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
// Get the Video's channel, fallback to the URL's channel id.
|
||||
const {channelId} = useParams();
|
||||
const {channel} = useChannel(video && video.channel_id ? video.channel_id : channelId);
|
||||
const {comments, captions} = useVideoExtras(videoFile?.video?.id);
|
||||
|
||||
if (videoFile === null) {
|
||||
return <VideoPlaceholder/>;
|
||||
|
|
@ -236,11 +237,11 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
|
||||
const captionsPane = {
|
||||
menuItem: 'Captions', render: () => <TabPane>
|
||||
<pre>{video.caption || 'No captions available.'}</pre>
|
||||
<pre>{captions || 'No captions available.'}</pre>
|
||||
</TabPane>
|
||||
};
|
||||
|
||||
const {poster_file, info_json_file, comments} = video;
|
||||
const {poster_file, info_json_file} = video;
|
||||
const filesPane = {
|
||||
menuItem: 'Files', render: () => <TabPane>
|
||||
<h3>Video File</h3>
|
||||
|
|
|
|||
|
|
@ -12,15 +12,15 @@ import {
|
|||
Modal,
|
||||
ModalContent,
|
||||
ModalHeader,
|
||||
Popup,
|
||||
Segment
|
||||
} from "../Theme";
|
||||
import {ButtonGroup, Container, Dimmer, Dropdown, GridColumn, GridRow, Icon, Input} from "semantic-ui-react";
|
||||
import {
|
||||
APIButton,
|
||||
ErrorMessage,
|
||||
InfoPopup,
|
||||
HotspotToggle,
|
||||
InfoPopup,
|
||||
RefreshHeader,
|
||||
ThrottleToggle,
|
||||
Toggle,
|
||||
useMessageDismissal,
|
||||
|
|
@ -489,16 +489,6 @@ export function SettingsPage() {
|
|||
body = <ErrorMessage>Unable to fetch settings</ErrorMessage>
|
||||
}
|
||||
|
||||
const refreshButton = <APIButton
|
||||
icon='refresh'
|
||||
onClick={fetchConfigs}
|
||||
/>;
|
||||
const refreshPopupButton = <Popup
|
||||
content='Check if configs are valid'
|
||||
on='hover'
|
||||
trigger={refreshButton}
|
||||
/>;
|
||||
|
||||
const controlSegment = <Segment>
|
||||
<Header as='h3'>Control WROLPi</Header>
|
||||
<HotspotToggle/>
|
||||
|
|
@ -509,14 +499,11 @@ export function SettingsPage() {
|
|||
</Segment>;
|
||||
|
||||
const configsSegment = <Segment>
|
||||
<Grid columns={2}>
|
||||
<GridRow>
|
||||
<GridColumn>
|
||||
<Header as='h2'>Configs</Header>
|
||||
</GridColumn>
|
||||
<GridColumn textAlign='right'>{refreshPopupButton}</GridColumn>
|
||||
</GridRow>
|
||||
</Grid>
|
||||
<RefreshHeader
|
||||
header='Refresh'
|
||||
popupContents='Check if configs are valid'
|
||||
onRefresh={fetchConfigs}
|
||||
/>
|
||||
|
||||
<p>These configs control this WROLPi; they are the source of truth. Any changes to configs will be applied to
|
||||
the database when imported (typically at startup).</p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue