mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-14 05:22:59 +01:00
Compare commits
No commits in common. "2c03791db5b6ff0d79efae78aa6f4c441c7f243a" and "ace8fe7caaef835d998b2532e2c7bb439ae9e1bc" have entirely different histories.
2c03791db5
...
ace8fe7caa
@ -1,7 +1,8 @@
|
||||
import cookieParser from "cookie-parser";
|
||||
import cors from "cors";
|
||||
import errorHandler from "errorhandler";
|
||||
import express from "express";
|
||||
|
||||
import createError from "http-errors";
|
||||
import morgan from "morgan";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
@ -19,11 +20,10 @@ app.use(
|
||||
);
|
||||
|
||||
app.set("port", process.env.PORT || 3000);
|
||||
if (process.env.ACCESS_LOG == "true") {
|
||||
app.use(
|
||||
morgan("dev", { stream: { write: (message) => logger.debug(message) } })
|
||||
);
|
||||
}
|
||||
|
||||
// app.use(
|
||||
// morgan("dev", { stream: { write: (message) => logger.debug(message) } })
|
||||
// );
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
@ -36,4 +36,15 @@ app.use("/v2/api/", apiV2Router);
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
|
||||
// error handler
|
||||
if (app.get("env") == "development") {
|
||||
// catch 404 and forward to error handler
|
||||
app.use((req, res, next) => {
|
||||
next(createError(404));
|
||||
});
|
||||
|
||||
// only use in development
|
||||
app.use(errorHandler());
|
||||
}
|
||||
|
||||
export default app;
|
||||
|
@ -1,21 +1,16 @@
|
||||
import "./env.js";
|
||||
|
||||
import errorHandler from "errorhandler";
|
||||
import figlet from "figlet";
|
||||
import createError from "http-errors";
|
||||
import kleur from "kleur";
|
||||
import "./env.js";
|
||||
import app from "./app.js";
|
||||
import logger from "./config/winston.js";
|
||||
import postInit from "./postInit.js";
|
||||
import figlet from "figlet";
|
||||
import kleur from "kleur";
|
||||
|
||||
/**
|
||||
* Error Handler. Provides full stack
|
||||
*/
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
app.use(errorHandler());
|
||||
app.use((req, res, next) => {
|
||||
next(createError(404));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,7 +22,7 @@ const server = app.listen(app.get("port"), () => {
|
||||
`App is running at ` +
|
||||
kleur.green().bold(`http://localhost:${app.get("port")}`) +
|
||||
" in " +
|
||||
kleur.green().bold(process.env.NODE_ENV || "production") +
|
||||
kleur.green().bold(app.get("env") as string) +
|
||||
" mode"
|
||||
);
|
||||
logger.info(kleur.red().bold("Press CTRL-C to stop"));
|
||||
|
@ -343,7 +343,7 @@ export async function chunkedUpload(
|
||||
const finalDestination = config.url + getEndpoint(config) + webdavPath;
|
||||
const status = statusTools.getStatus();
|
||||
status.status = States.BKUP_UPLOAD_CLOUD;
|
||||
status.progress = -1;
|
||||
status.progress = 0;
|
||||
statusTools.setStatus(status);
|
||||
try {
|
||||
await initChunkedUpload(chunkedUrl, finalDestination, config);
|
||||
@ -365,21 +365,16 @@ export async function chunkedUpload(
|
||||
logger.error((err as Error).message);
|
||||
}
|
||||
fs.unlinkSync(localPath);
|
||||
const status = statusTools.getStatus();
|
||||
status.status = States.IDLE;
|
||||
status.progress = undefined;
|
||||
statusTools.setStatus(status);
|
||||
throw err;
|
||||
}
|
||||
|
||||
let start = 0;
|
||||
let end = Math.min(CHUNK_SIZE - 1, fileSize - 1);
|
||||
|
||||
let current_size = end + 1;
|
||||
let end = fileSize > CHUNK_SIZE ? CHUNK_SIZE : fileSize;
|
||||
let current_size = end;
|
||||
// const uploadedBytes = 0;
|
||||
|
||||
let i = 1;
|
||||
while (start < fileSize - 1) {
|
||||
let i = 0;
|
||||
while (start < fileSize) {
|
||||
const chunk = fs.createReadStream(localPath, { start, end });
|
||||
try {
|
||||
const chunckNumber = i.toString().padStart(CHUNK_NUMBER_SIZE, "0");
|
||||
@ -391,9 +386,9 @@ export async function chunkedUpload(
|
||||
fileSize,
|
||||
config
|
||||
);
|
||||
start = end + 1;
|
||||
end = Math.min(start + CHUNK_SIZE - 1, fileSize - 1);
|
||||
current_size = end - start + 1;
|
||||
start = end;
|
||||
end = Math.min(start + CHUNK_SIZE, fileSize - 1);
|
||||
current_size = end - start;
|
||||
i++;
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
@ -413,10 +408,6 @@ export async function chunkedUpload(
|
||||
logger.error(`Code: ${(error as PlainResponse).statusCode}`);
|
||||
logger.error(`Body: ${(error as PlainResponse).body as string}`);
|
||||
}
|
||||
const status = statusTools.getStatus();
|
||||
status.status = States.IDLE;
|
||||
status.progress = undefined;
|
||||
statusTools.setStatus(status);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -444,10 +435,6 @@ export async function chunkedUpload(
|
||||
logger.error((err as Error).message);
|
||||
}
|
||||
fs.unlinkSync(localPath);
|
||||
const status = statusTools.getStatus();
|
||||
status.status = States.IDLE;
|
||||
status.progress = undefined;
|
||||
statusTools.setStatus(status);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@ -465,7 +452,6 @@ export function uploadChunk(
|
||||
logger.debug(`...URI: ${encodeURI(url)}`);
|
||||
logger.debug(`...Final destination: ${encodeURI(finalDestination)}`);
|
||||
logger.debug(`...Chunk size: ${contentLength}`);
|
||||
logger.debug(`...Total size: ${totalLength}`);
|
||||
got.stream
|
||||
.put(url, {
|
||||
headers: {
|
||||
|
@ -1,37 +1,35 @@
|
||||
<template>
|
||||
<v-fade-transition>
|
||||
<div id="parent" v-if="alertVisible">
|
||||
<div id="alertContainer">
|
||||
<v-slide-x-transition group tag="div">
|
||||
<v-alert
|
||||
v-for="alert of alertList"
|
||||
v-bind:key="alert.id"
|
||||
elevation="24"
|
||||
:type="alert.type"
|
||||
border="start"
|
||||
class="mb-2"
|
||||
>
|
||||
<v-row dense>
|
||||
<v-col v-html="alert.message"></v-col>
|
||||
<v-col cols="2">
|
||||
<v-btn
|
||||
class="d-inline"
|
||||
size="30"
|
||||
variant="text"
|
||||
rounded
|
||||
icon="$close"
|
||||
@click="alertStore.remove(alert.id)"
|
||||
></v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<div id="alertContainer" v-if="alertVisible">
|
||||
<v-slide-x-transition group tag="div">
|
||||
<v-alert
|
||||
v-for="alert of alertList"
|
||||
v-bind:key="alert.id"
|
||||
elevation="24"
|
||||
:type="alert.type"
|
||||
border="start"
|
||||
class="mb-2"
|
||||
>
|
||||
<v-row dense>
|
||||
<v-col v-html="alert.message"></v-col>
|
||||
<v-col cols="2">
|
||||
<v-btn
|
||||
class="d-inline"
|
||||
size="30"
|
||||
variant="text"
|
||||
rounded
|
||||
icon="$close"
|
||||
@click="alertStore.remove(alert.id)"
|
||||
></v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<v-progress-linear
|
||||
:max="alertStore.timeOutValue"
|
||||
:model-value="alert.timeOut"
|
||||
></v-progress-linear>
|
||||
</v-alert>
|
||||
</v-slide-x-transition>
|
||||
</div>
|
||||
<v-progress-linear
|
||||
:max="alertStore.timeOutValue"
|
||||
:model-value="alert.timeOut"
|
||||
></v-progress-linear>
|
||||
</v-alert>
|
||||
</v-slide-x-transition>
|
||||
</div>
|
||||
</v-fade-transition>
|
||||
</template>
|
||||
@ -47,17 +45,11 @@ const { alertList } = storeToRefs(alertStore);
|
||||
const alertVisible = computed(() => alertList.value.length > 0);
|
||||
</script>
|
||||
<style>
|
||||
#parent {
|
||||
#alertContainer {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
right: 20px;
|
||||
z-index: 99999;
|
||||
height: 100vh;
|
||||
#alertContainer {
|
||||
position: sticky;
|
||||
top: 80px;
|
||||
right: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@/store/alert
|
||||
|
@ -32,9 +32,9 @@
|
||||
<script setup lang="ts">
|
||||
import { useMenuSize } from "@/composable/menuSize";
|
||||
import { deleteWebdabBackup } from "@/services/webdavService";
|
||||
import { useAlertStore } from "@/store/alert";
|
||||
import type { WebdavBackup } from "@/types/webdav";
|
||||
import { ref } from "vue";
|
||||
import { computed, ref } from "vue";
|
||||
import { useDisplay } from "vuetify/dist/vuetify";
|
||||
|
||||
const dialog = ref(false);
|
||||
const loading = ref(false);
|
||||
@ -42,11 +42,6 @@ const item = ref<WebdavBackup | null>(null);
|
||||
|
||||
const { width, isFullScreen } = useMenuSize();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "deleted"): void;
|
||||
}>();
|
||||
|
||||
const alertStore = useAlertStore();
|
||||
function confirm() {
|
||||
loading.value = true;
|
||||
if (item.value) {
|
||||
@ -54,12 +49,9 @@ function confirm() {
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
dialog.value = false;
|
||||
alertStore.add("success", "Backup deleted from cloud");
|
||||
emit("deleted");
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
alertStore.add("error", "Fail to deleted backup from cloud");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +76,7 @@
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<cloud-delete-dialog
|
||||
ref="deleteDialog"
|
||||
@deleted="refreshBackup"
|
||||
></cloud-delete-dialog>
|
||||
<cloud-delete-dialog ref="deleteDialog"></cloud-delete-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -69,3 +69,4 @@ function saved() {
|
||||
alertStore.add("success", "Backup settings saved !");
|
||||
}
|
||||
</script>
|
||||
@/store/dialogStatus@/store/alert
|
||||
|
Loading…
Reference in New Issue
Block a user