mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +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 LOCAL_FORAGE_KEY = "interactive";
|
||||||
|
const TIME_BETWEEN_SYNCS = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
interface IInteractiveState {
|
interface IInteractiveState {
|
||||||
serverOffset: number;
|
serverOffset: number;
|
||||||
|
lastSyncTime: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InteractiveProvider: React.FC = ({ children }) => {
|
export const InteractiveProvider: React.FC = ({ children }) => {
|
||||||
const [{ data: config }, setConfig] = useLocalForage<IInteractiveState>(
|
const [{ data: config }, setConfig] = useLocalForage<IInteractiveState>(
|
||||||
LOCAL_FORAGE_KEY,
|
LOCAL_FORAGE_KEY,
|
||||||
{ serverOffset: 0 }
|
{ serverOffset: 0, lastSyncTime: 0 }
|
||||||
);
|
);
|
||||||
|
|
||||||
const { configuration: stashConfig } = React.useContext(ConfigurationContext);
|
const { configuration: stashConfig } = React.useContext(ConfigurationContext);
|
||||||
|
|
@ -91,13 +93,17 @@ export const InteractiveProvider: React.FC = ({ children }) => {
|
||||||
const initialise = useCallback(async () => {
|
const initialise = useCallback(async () => {
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
|
|
||||||
if (!config?.serverOffset) {
|
const shouldResync =
|
||||||
|
!config?.lastSyncTime ||
|
||||||
|
Date.now() - config?.lastSyncTime > TIME_BETWEEN_SYNCS;
|
||||||
|
|
||||||
|
if (!config?.serverOffset || shouldResync) {
|
||||||
setState(ConnectionState.Syncing);
|
setState(ConnectionState.Syncing);
|
||||||
const offset = await interactive.sync();
|
const offset = await interactive.sync();
|
||||||
setConfig({ serverOffset: offset });
|
setConfig({ serverOffset: offset, lastSyncTime: Date.now() });
|
||||||
setState(ConnectionState.Ready);
|
}
|
||||||
setInitialised(true);
|
|
||||||
} else {
|
if (config?.serverOffset) {
|
||||||
interactive.setServerTimeOffset(config.serverOffset);
|
interactive.setServerTimeOffset(config.serverOffset);
|
||||||
setState(ConnectionState.Connecting);
|
setState(ConnectionState.Connecting);
|
||||||
try {
|
try {
|
||||||
|
|
@ -159,7 +165,7 @@ export const InteractiveProvider: React.FC = ({ children }) => {
|
||||||
|
|
||||||
setState(ConnectionState.Syncing);
|
setState(ConnectionState.Syncing);
|
||||||
const offset = await interactive.sync();
|
const offset = await interactive.sync();
|
||||||
setConfig({ serverOffset: offset });
|
setConfig({ serverOffset: offset, lastSyncTime: Date.now() });
|
||||||
setState(ConnectionState.Ready);
|
setState(ConnectionState.Ready);
|
||||||
}, [interactive, state, setConfig, initialised]);
|
}, [interactive, state, setConfig, initialised]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue