Skip to content

Commit

Permalink
Show server configs in info side menu
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Dec 14, 2024
1 parent 465f5f5 commit f882904
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 77 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy-dashboard": "pnpm run --filter r2-explorer-dashboard deploy",
"deploy-dashboard-dev": "pnpm run --filter r2-explorer-dashboard deploy-dev",
"deploy-dev-worker": "pnpm run --filter r2-explorer-dev-worker deploy",
"publish-npm": "pnpm run --filter worker publish"
"package": "pnpm run --filter worker package"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
Expand Down
103 changes: 49 additions & 54 deletions packages/dashboard/src/components/main/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,62 +45,35 @@
<q-btn class="q-mb-sm" @click="gotoFiles" color="blue" icon="folder_copy" label="Files" stack />
<q-btn class="q-mb-sm" @click="gotoEmail" color="blue" icon="email" label="Email" stack />

<!-- <q-btn class="q-mb-sm q-mt-auto q-mb-0" @click="settingsPopup=true" color="secondary" icon="settings" label="Server"-->
<!-- stack />-->
<q-btn class="q-mb-sm q-mt-auto q-mb-0" @click="upgradePopup=true" color="secondary" icon="question_mark" label="Info"
<q-btn class="q-mb-sm q-mt-auto q-mb-0" @click="infoPopup=true" color="secondary" icon="question_mark"
label="Info"
stack />
</div>
</div>

<q-dialog v-model="upgradePopup" persistent no-esc-dismiss no-route-dismiss no-backdrop-dismiss>
<q-dialog v-model="infoPopup" persistent no-route-dismiss>
<q-card>
<q-card-section>
<div class="text-h6">🎉 Welcome to the new Dashboard v2! 🚀</div>
<div class="text-h6">🎉 Thank you for using R2-Explorer! 🚀</div>
</q-card-section>

<q-card-section class="q-pt-none">
We're thrilled to introduce our revamped interface, designed to enhance your experience and productivity. As you
explore the new features and improvements, feel free to provide feedback or report any issues you encounter.
Your input helps us fine-tune the dashboard to meet your needs better.<br>
You are running version <b>{{ mainStore.version }}</b><br>
<template v-if="updateAvailable">
Latest version is <b>{{latestVersion}}</b>, learn how to <a href="https://r2explorer.dev/getting-started/updating-your-project/" target="_blank">update your instance here</a>.<br>
</template>
<br>
To revisit this message in the future, simply click on the question mark icon located in the left corner. Your
feedback is invaluable to us, so don't hesitate to reach out with any thoughts or concerns.<br>
<br>
Please report issues here: <a href="https://github.com/G4brym/R2-Explorer/issues" target="_blank">https://github.com/G4brym/R2-Explorer/issues</a><br>
<br>
If you would like to continue using the old Dashboard, please follow this <a
href="https://r2explorer.dev/guides/continue-using-legacy-dashboard/" target="_blank">guide from the
documentation</a><br>
<br>
Thank you for being a part of our journey towards excellence! 🌟<br>
<br>
Best regards<br>
</q-card-section>

<q-card-actions align="right">
<q-btn flat label="OK" color="primary" v-close-popup />
</q-card-actions>
</q-card>
</q-dialog>

<q-dialog v-model="settingsPopup">
<q-card>
<q-card-section>
<div class="text-h6">Your server configurations</div>
</q-card-section>

<q-card-section class="q-pt-none">
<q-input
filled
disable
v-if="mainStore.username"
v-model="mainStore.username"
/>
<q-input
filled
disable
:model-value="mainStore.version"
/>
<template v-if="mainStore.auth">
<b>Authentication</b><br>
Method: {{ mainStore.auth.type }}<br>
Username: {{ mainStore.auth.username }}
</template>
<template v-else>
Not authenticated
</template>
<br><br>
<b>Server Configuration</b><br>
{{ JSON.stringify(mainStore.config, null, 2) }}
</q-card-section>

<q-card-actions align="right">
Expand All @@ -122,8 +95,9 @@ import { defineComponent } from "vue";
export default defineComponent({
name: "LeftSidebar",
data: () => ({
upgradePopup: false,
settingsPopup: false,
infoPopup: false,
updateAvailable: false,
latestVersion: "",
}),
components: { CreateFolder, CreateFile },
methods: {
Expand All @@ -139,6 +113,24 @@ export default defineComponent({
params: { bucket: this.selectedBucket },
});
},
isUpdateAvailable: (currentVersion, latestVersion) => {
// Split versions into parts and convert to numbers
const current = currentVersion.split(".").map(Number);
const latest = latestVersion.split(".").map(Number);
// Compare major version
if (latest[0] > current[0]) return true;
if (latest[0] < current[0]) return false;
// Compare minor version
if (latest[1] > current[1]) return true;
if (latest[1] < current[1]) return false;
// Compare patch version
if (latest[2] > current[2]) return true;
return false;
},
},
computed: {
selectedBucket: function () {
Expand All @@ -148,12 +140,15 @@ export default defineComponent({
return this.$route.name.split("-")[0];
},
},
mounted: function () {
const alertSeen = localStorage.getItem("DASH_V2_ALERT");
if (!alertSeen) {
this.upgradePopup = true;
localStorage.setItem("DASH_V2_ALERT", true);
async mounted() {
const resp = await fetch(
"https://api.github.com/repos/G4brym/R2-Explorer/releases/latest",
);
const parsed = await resp.json();
const latestVersion = parsed.tag_name.replace("v", "");
if (this.isUpdateAvailable(this.mainStore.version, latestVersion)) {
this.latestVersion = latestVersion;
this.updateAvailable = true;
}
},
setup() {
Expand Down
12 changes: 5 additions & 7 deletions packages/dashboard/src/stores/main-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const useMainStore = defineStore("main", {
state: () => ({
// Config
apiReadonly: true,
authentication_type: "",
authentication_username: "",
auth: {},
config: {},
version: "",
showHiddenFiles: false,

Expand Down Expand Up @@ -37,11 +37,9 @@ export const useMainStore = defineStore("main", {
});

this.apiReadonly = response.data.config.readonly;
this.authentication_type =
response.data.config.auth?.authentication_type;
this.authentication_username =
response.data.config.auth?.authentication_username;
this.version = response.data.config.version;
this.config = response.data.config;
this.auth = response.data.auth;
this.version = response.data.version;
this.showHiddenFiles = response.data.config.showHiddenFiles;
} catch (error) {
console.log(error);
Expand Down
9 changes: 0 additions & 9 deletions packages/worker/dev/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ binding = 'teste'
bucket_name = 'teste'
preview_bucket_name = 'teste'

[[r2_buckets]]
binding = 'storage'
bucket_name = 'storage'
preview_bucket_name = 'storage'

[[r2_buckets]]
binding = 'drive'
bucket_name = 'drive'
preview_bucket_name = 'drive'
6 changes: 3 additions & 3 deletions packages/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "r2-explorer",
"version": "1.1.0",
"description": "A Google Drive Interface for your Cloudflare R2 Buckets",
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dashboard",
"dist",
Expand Down
19 changes: 18 additions & 1 deletion packages/worker/src/modules/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import type { AppContext } from "../types";

export function dashboardIndex(c: AppContext) {
return c.text("your index.html is not loaded!");
if (c.env.ASSETS === undefined) {
return c.text(
"ASSETS binding is not defined, learn more here: https://r2explorer.dev/guides/migrating-to-1.1/",
500,
);
}

return c.text(
"ASSETS binding is not pointing to a valid dashboard, learn more here: https://r2explorer.dev/guides/migrating-to-1.1/",
500,
);
}

export async function dashboardRedirect(c: AppContext, next) {
if (c.env.ASSETS === undefined) {
return c.text(
"ASSETS binding is not defined, learn more here: https://r2explorer.dev/guides/migrating-to-1.1/",
500,
);
}

const url = new URL(c.req.url);

if (!url.pathname.includes(".")) {
Expand Down
4 changes: 2 additions & 2 deletions packages/worker/src/modules/server/getInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class GetInfo extends OpenAPIRoute {
config: config,
auth: c.get("authentication_type")
? {
authentication_type: c.get("authentication_type"),
authentication_username: c.get("authentication_username"),
type: c.get("authentication_type"),
username: c.get("authentication_username"),
}
: undefined,
};
Expand Down
1 change: 1 addition & 0 deletions packages/worker/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type R2ExplorerConfig = {
};

export type AppEnv = {
ASSETS: Fetcher;
[key: string]: R2Bucket;
};
export type AppVariables = {
Expand Down

0 comments on commit f882904

Please sign in to comment.