diff --git a/src/dashboard.py b/src/dashboard.py index 052a340..afaf05d 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -346,6 +346,7 @@ class PeerShareLink: self.Configuration = Configuration self.ShareDate = ShareDate self.ExpireDate = ExpireDate + def toJson(self): return { @@ -358,10 +359,10 @@ class PeerShareLink: class PeerShareLinks: def __init__(self): self.Links: list[PeerShareLink] = [] - - existingTables = cursor.execute("SELECT name FROM sqlite_master WHERE type='table' and name = 'PeerShareLinks'").fetchall() + self.PeerShareLinkCursor = sqldb.cursor() + existingTables = self.PeerShareLinkCursor.execute("SELECT name FROM sqlite_master WHERE type='table' and name = 'PeerShareLinks'").fetchall() if len(existingTables) == 0: - cursor.execute( + self.PeerShareLinkCursor.execute( """ CREATE TABLE PeerShareLinks ( ShareID VARCHAR NOT NULL PRIMARY KEY, Configuration VARCHAR NOT NULL, Peer VARCHAR NOT NULL, @@ -375,26 +376,28 @@ class PeerShareLinks: # print(self.Links) def __getSharedLinks(self): self.Links.clear() - allLinks = cursor.execute("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall() + allLinks = self.PeerShareLinkCursor.execute("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall() for link in allLinks: self.Links.append(PeerShareLink(*link)) def getLink(self, Configuration: str, Peer: str) -> list[PeerShareLink]: + self.__getSharedLinks() return list(filter(lambda x : x.Configuration == Configuration and x.Peer == Peer, self.Links)) def getLinkByID(self, ShareID: str) -> list[PeerShareLink]: + self.__getSharedLinks() return list(filter(lambda x : x.ShareID == ShareID, self.Links)) def addLink(self, Configuration: str, Peer: str, ExpireDate: datetime = None) -> tuple[bool, str]: try: newShareID = str(uuid.uuid4()) if len(self.getLink(Configuration, Peer)) > 0: - cursor.execute("UPDATE PeerShareLinks SET ExpireDate = datetime('now', 'localtime') WHERE Configuration = ? AND Peer = ?", (Configuration, Peer, )) + self.PeerShareLinkCursor.execute("UPDATE PeerShareLinks SET ExpireDate = datetime('now', 'localtime') WHERE Configuration = ? AND Peer = ?", (Configuration, Peer, )) - if ExpireDate is not None: - ExpireDate = datetime.strptime(ExpireDate, '%Y-%m-%d %H:%M:%S') - - cursor.execute("INSERT INTO PeerShareLinks (ShareID, Configuration, Peer, ExpireDate) VALUES (?, ?, ?, ?)", (newShareID, Configuration, Peer, ExpireDate, )) + # if ExpireDate is not None: + # ExpireDate = datetime.strptime(ExpireDate, '%Y-%m-%d %H:%M:%S') + + self.PeerShareLinkCursor.execute("INSERT INTO PeerShareLinks (ShareID, Configuration, Peer, ExpireDate) VALUES (?, ?, ?, ?)", (newShareID, Configuration, Peer, ExpireDate, )) sqldb.commit() self.__getSharedLinks() except Exception as e: @@ -402,16 +405,11 @@ class PeerShareLinks: return True, newShareID def updateLinkExpireDate(self, ShareID, ExpireDate: datetime = None) -> tuple[bool, str]: - try: - if ExpireDate is None: - cursor.execute("UPDATE PeerShareLinks SET ExpireDate = datetime('now', 'localtime') WHERE ShareID = ?", (ShareID, )) - else: - cursor.execute("UPDATE PeerShareLinks SET ExpireDate = ? WHERE ShareID = ?", (ShareID, datetime.strptime(ExpireDate, '%Y-%m-%d %H:%M:%S'), )) - sqldb.commit() - self.__getSharedLinks() - return True - except Exception as e: - return False, str(e) + + self.PeerShareLinkCursor.execute("UPDATE PeerShareLinks SET ExpireDate = ? WHERE ShareID = ?;", (ExpireDate, ShareID, )) + sqldb.commit() + self.__getSharedLinks() + return True, "" @@ -1511,7 +1509,7 @@ def API_newDashboardAPIKey(): if data['neverExpire']: expiredAt = None else: - expiredAt = datetime.strptime(data['ExpiredAt'], '%Y-%m-%dT%H:%M:%S') + expiredAt = datetime.strptime(data['ExpiredAt'], '%Y-%m-%d %H:%M:%S') DashboardConfig.createAPIKeys(expiredAt) return ResponseObject(True, data=DashboardConfig.DashboardAPIKeys) except Exception as e: @@ -1594,6 +1592,8 @@ def API_sharePeer_update(): data: dict[str, str] = request.get_json() ShareID: str = data.get("ShareID") ExpireDate: str = data.get("ExpireDate") + print(ShareID) + print(ExpireDate) if ShareID is None: return ResponseObject(False, "Please specify ShareID") diff --git a/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue b/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue index ba72f41..04165c9 100644 --- a/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue +++ b/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue @@ -3,10 +3,12 @@ import ScheduleDropdown from "@/components/configurationComponents/peerScheduleJ import {ref} from "vue"; import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js"; import {fetchPost} from "@/utilities/fetch.js"; +import VueDatePicker from "@vuepic/vue-datepicker"; +import dayjs from "dayjs"; export default { name: "schedulePeerJob", - components: {ScheduleDropdown}, + components: {VueDatePicker, ScheduleDropdown}, props: { dropdowns: Array[Object], pjob: Object, @@ -94,6 +96,11 @@ export default { }) } this.$emit('delete') + }, + parseTime(modelData){ + if(modelData){ + this.job.Value = dayjs(modelData).format("YYYY-MM-DD HH:mm:ss"); + } } }, } @@ -128,12 +135,26 @@ export default { :data="this.job.Operator" @update="(value) => this.job.Operator = value" > - + + + + + + + + + \ No newline at end of file diff --git a/src/static/app/src/components/configurationComponents/peerShareLinkModal.vue b/src/static/app/src/components/configurationComponents/peerShareLinkModal.vue index 8c781b3..7555acd 100644 --- a/src/static/app/src/components/configurationComponents/peerShareLinkModal.vue +++ b/src/static/app/src/components/configurationComponents/peerShareLinkModal.vue @@ -27,17 +27,28 @@ export default { mounted() { this.dataCopy = JSON.parse(JSON.stringify(this.peer.ShareLink)).at(0); }, + watch: { + 'peer.ShareLink': { + deep: true, + handler(newVal, oldVal){ + if (oldVal.length !== newVal.length){ + this.dataCopy = JSON.parse(JSON.stringify(this.peer.ShareLink)).at(0); + } + } + } + }, + methods: { startSharing(){ this.loading = true; fetchPost("/api/sharePeer/create", { Configuration: this.peer.configuration.Name, Peer: this.peer.id, - ExpireDate: dayjs().add(30, 'd').format("YYYY-MM-DD hh:mm:ss") + ExpireDate: dayjs().add(7, 'd').format("YYYY-MM-DD HH:mm:ss") }, (res) => { if (res.status){ this.peer.ShareLink = res.data; - this.dataCopy = res.data; + this.dataCopy = res.data.at(0); this.store.newMessage("Server", "Share link created successfully", "success") }else{ this.store.newMessage("Server", @@ -49,8 +60,29 @@ export default { }, updateLinkExpireDate(){ fetchPost("/api/sharePeer/update", this.dataCopy, (res) => { - console.log(res) - }) + if (res.status){ + this.dataCopy = res.data.at(0) + this.peer.ShareLink = res.data; + this.store.newMessage("Server", "Link expire date updated", "success") + }else{ + this.store.newMessage("Server", + "Link expire date failed to update. Reason: " + res.message, "danger") + } + this.loading = false + }); + }, + stopSharing(){ + this.loading = true; + this.dataCopy.ExpireDate = dayjs().format("YYYY-MM-DD HH:mm:ss") + this.updateLinkExpireDate() + }, + parseTime(modelData){ + if(modelData){ + this.dataCopy.ExpireDate = dayjs(modelData).format("YYYY-MM-DD HH:mm:ss"); + }else{ + this.dataCopy.ExpireDate = undefined + } + this.updateLinkExpireDate() } }, computed: { @@ -60,11 +92,6 @@ export default { + this.$router.resolve( {path: "/share", query: {"ShareID": this.dataCopy.ShareID}}).href; } - }, - watch: { - 'dataCopy.ExpireDate'(){ - this.updateLinkExpireDate() - } } } @@ -101,16 +128,31 @@ export default { {{ getUrl }} -
+
Expire Date -
+
diff --git a/src/static/app/src/components/settingsComponent/dashboardAPIKeysComponents/newDashboardAPIKey.vue b/src/static/app/src/components/settingsComponent/dashboardAPIKeysComponents/newDashboardAPIKey.vue index 2dfa9ec..ff018d1 100644 --- a/src/static/app/src/components/settingsComponent/dashboardAPIKeysComponents/newDashboardAPIKey.vue +++ b/src/static/app/src/components/settingsComponent/dashboardAPIKeysComponents/newDashboardAPIKey.vue @@ -2,13 +2,15 @@ import dayjs from "dayjs"; import {fetchPost} from "@/utilities/fetch.js"; import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js"; +import VueDatePicker from "@vuepic/vue-datepicker"; export default { name: "newDashboardAPIKey", + components: {VueDatePicker}, data(){ return{ newKeyData:{ - ExpiredAt: dayjs().add(1, 'd').format("YYYY-MM-DDTHH:mm:ss"), + ExpiredAt: dayjs().add(7, 'd').format("YYYY-MM-DD HH:mm:ss"), neverExpire: false }, submitting: false @@ -39,6 +41,13 @@ export default { fixDate(date){ console.log(dayjs(date).format("YYYY-MM-DDTHH:mm:ss")) return dayjs(date).format("YYYY-MM-DDTHH:mm:ss") + }, + parseTime(modelData){ + if(modelData){ + this.newKeyData.ExpiredAt = dayjs(modelData).format("YYYY-MM-DD HH:mm:ss"); + }else{ + this.newKeyData.ExpiredAt = undefined + } } } } @@ -49,16 +58,23 @@ export default { style="background-color: #00000060; backdrop-filter: blur(3px)">
- Create API Key +
Create API Key
When should this API Key expire?
- +