mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 16:34:02 +01:00
Automatically resync Handy (#5581)
* Resync Handy every hour * Don't try to upload script after resync if Handy is disconnected
This commit is contained in:
parent
9f7d00d83f
commit
b0a10399d7
1 changed files with 13 additions and 7 deletions
|
|
@ -62,15 +62,17 @@ export const InteractiveContext = React.createContext<IState>({
|
|||
});
|
||||
|
||||
const LOCAL_FORAGE_KEY = "interactive";
|
||||
const TIME_BETWEEN_SYNCS = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
interface IInteractiveState {
|
||||
serverOffset: number;
|
||||
lastSyncTime: number;
|
||||
}
|
||||
|
||||
export const InteractiveProvider: React.FC = ({ children }) => {
|
||||
const [{ data: config }, setConfig] = useLocalForage<IInteractiveState>(
|
||||
LOCAL_FORAGE_KEY,
|
||||
{ serverOffset: 0 }
|
||||
{ serverOffset: 0, lastSyncTime: 0 }
|
||||
);
|
||||
|
||||
const { configuration: stashConfig } = React.useContext(ConfigurationContext);
|
||||
|
|
@ -91,13 +93,17 @@ export const InteractiveProvider: React.FC = ({ children }) => {
|
|||
const initialise = useCallback(async () => {
|
||||
setError(undefined);
|
||||
|
||||
if (!config?.serverOffset) {
|
||||
const shouldResync =
|
||||
!config?.lastSyncTime ||
|
||||
Date.now() - config?.lastSyncTime > TIME_BETWEEN_SYNCS;
|
||||
|
||||
if (!config?.serverOffset || shouldResync) {
|
||||
setState(ConnectionState.Syncing);
|
||||
const offset = await interactive.sync();
|
||||
setConfig({ serverOffset: offset });
|
||||
setState(ConnectionState.Ready);
|
||||
setInitialised(true);
|
||||
} else {
|
||||
setConfig({ serverOffset: offset, lastSyncTime: Date.now() });
|
||||
}
|
||||
|
||||
if (config?.serverOffset) {
|
||||
interactive.setServerTimeOffset(config.serverOffset);
|
||||
setState(ConnectionState.Connecting);
|
||||
try {
|
||||
|
|
@ -159,7 +165,7 @@ export const InteractiveProvider: React.FC = ({ children }) => {
|
|||
|
||||
setState(ConnectionState.Syncing);
|
||||
const offset = await interactive.sync();
|
||||
setConfig({ serverOffset: offset });
|
||||
setConfig({ serverOffset: offset, lastSyncTime: Date.now() });
|
||||
setState(ConnectionState.Ready);
|
||||
}, [interactive, state, setConfig, initialised]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue