Skip to content

Commit

Permalink
Merge pull request #65 from TetrisIQ/feat/preRelease
Browse files Browse the repository at this point in the history
Feat/pre release
  • Loading branch information
TetrisIQ authored Apr 26, 2022
2 parents fdf71c5 + 989a2e5 commit 0743fa9
Show file tree
Hide file tree
Showing 81 changed files with 4,161 additions and 511 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**/node_modules
**/dist
**/data.json
**/data
**/radata
**/cypress
.github
.vscode
.idea
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/node_modules/
/dist/
/.vscode/
.DS_Store
/.idea/
/cypress/screenshots/
/cypress/videos/
/**/dist/
/relay/radata/
/relay/data/
/relay/data.json/
/.env.local
/**/node_modules/
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Build Project
FROM node:14-alpine as builder
RUN mkdir /work
WORKDIR /work
#RUN apk add --no-cache alpine-sdk python3
COPY frontend ./frontend
WORKDIR /work/frontend
RUN echo "Build frontend"
RUN mkdir -p "node_modules"
RUN yarn install
RUN VITE_RELAY=http://localhost:8765/gun yarn build

WORKDIR /work
COPY relay ./relay
WORKDIR /work/relay
RUN echo "Build Relay Server"
RUN mkdir -p "node_modules"
RUN yarn install
RUN yarn build
RUN ls

# fresh image without dev packages
FROM node:14-alpine
# build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE
ARG VCS_REF
ARG VCS_URL
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Poddle - Meetings made simple!" \
org.label-schema.url="https://poddle.network" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.vendor="The poddle Team" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
ARG SHA
RUN mkdir /work
WORKDIR /work
COPY --from=builder /work/frontend/node_modules ./node_modules
COPY --from=builder /work/relay/node_modules ./relay/node_modules
COPY --from=builder /work/frontend/dist ./dist
COPY --from=builder /work/relay/dist ./relay/dist
COPY --from=builder /work/relay/package.json ./relay/package.json
RUN echo "{ \"sha\": \"$SHA\" }" > version.json
RUN cat version.json
WORKDIR /work/relay
RUN ls
EXPOSE 8765
CMD ["npm","start"]
4 changes: 0 additions & 4 deletions cypress.json

This file was deleted.

4 changes: 2 additions & 2 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
// module.exports = (on, config) => {
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// }
}
12 changes: 12 additions & 0 deletions frontend/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"projectId": "byzw5k",
"fixturesFolder": "../cypress/fixtures",
"integrationFolder": "../cypress/integration",
"pluginsFile": "../cypress/plugins/index.js",
"screenshotsFolder": "../cypress/screenshots",
"videosFolder": "../cypress/videos",
"downloadsFolder": "../cypress/downloads",
"supportFile": "../cypress/support/index.js"


}
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json → frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "APP_ENV=local vite",
"build": "vite build --base /",
"preview": "vite preview",
"cypressUI": "cypress open",
Expand All @@ -24,6 +24,7 @@
"svelte-preprocess": "^4.10.1",
"tailwindcss": "^3.0.12",
"tslib": "^2.3.1",
"tui-calendar": "^1.15.3",
"typescript": "^4.4.4",
"vite": "^2.7.2"
},
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/App.svelte → frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import {gun} from "./gun";
import NewMessage from "./view/NewMessage.svelte";
import dayjs from "dayjs";
import {onMount} from "svelte";
import Modal from "./lib/Modal.svelte";
if (window.location.search.includes("?k=")) {
page.set(Poll)
Expand Down Expand Up @@ -55,6 +57,7 @@
{/if}
<main class="mx-auto flex-grow w-full xl:px-40 l:px-14 text-center">
<NotificationArea/>
<Modal/>
<svelte:component this={$page}/>
</main>
<Footer/>
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
128 changes: 128 additions & 0 deletions frontend/src/gun/LStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {uuidv4} from "../lib/util";
import type {Poll} from "../model/Poll";
import type {Dayjs} from "dayjs";

export type MyPoll = { id: string, password: string, title: string, participants: number, deadline: Dayjs, created: Dayjs, percent?: string }

class LStore {

setMyName(name: string) {
localStorage.setItem("name", name);
}

getMyName(): string {
const name = localStorage.getItem("name")
if (name === null) {
return "Anonymous"
} else {
return name;
}
}

getClientID() {
const clientId = localStorage.getItem("clientID")
if (clientId === null) {
const id = uuidv4().slice(0, 5)
localStorage.setItem("clientID", id)
return id
} else {
return clientId;
}
}

getMyPolls(): Array<MyPoll> {
const myPolls = localStorage.getItem("myPolls")
if (myPolls === null) {
return [];
}
return JSON.parse(myPolls)
}

addPercentToPoll(poll: MyPoll): Array<MyPoll> {
if (poll.percent !== undefined) {
const myPolls: Array<MyPoll> = this.getMyPolls();
const pollWithSameId: MyPoll = myPolls.find(p => p.id === poll.id);
const index = myPolls.indexOf(pollWithSameId)
if (index !== -1) {
myPolls[index] = poll;
localStorage.setItem("myPolls", JSON.stringify(myPolls))
return myPolls;
}
}
return this.getMyPolls()
}

addMyPoll(poll: Poll): boolean {
if (poll.id === "" && poll.password === "") {
return false;
}
const myPolls: Array<MyPoll> = this.getMyPolls();
if (myPolls.find(value => value.id === poll.id) !== undefined) {
// Update polls
const pollWithSameId: MyPoll = myPolls.find(p => p.id === poll.id);
const index = myPolls.indexOf(pollWithSameId)
if (index !== -1) {
myPolls[index] = {
id: poll.id,
title: poll.title,
participants: poll.participants.length,
password: poll.password,
deadline: poll.deadline,
created: poll.created
}
}
} else {
myPolls.push({
id: poll.id,
title: poll.title,
participants: poll.participants.length,
password: poll.password,
deadline: poll.deadline,
created: poll.created
})
}
localStorage.setItem("myPolls", JSON.stringify(myPolls))
return true;
}

removeMyPoll(poll) {
if (poll !== undefined) {
const myPolls: Array<MyPoll> = this.getMyPolls();
const pollWithSameId: MyPoll = myPolls.find(p => p.id === poll.id);
const index = myPolls.indexOf(pollWithSameId)
if (index > -1) {
myPolls.splice(index, 1); // 2nd parameter means remove one item only
}
localStorage.setItem("myPolls", JSON.stringify(myPolls))
return myPolls;
}
return this.getMyPolls();
}

setUsername(name: string) {
if (name === null) {
localStorage.removeItem("username")
} else {
localStorage.setItem("username", name);
}
}

getUsername(): string {
return localStorage.getItem("username")
}

setPassword(password: string) {
if (password === null) {
localStorage.removeItem("_p")
} else {
localStorage.setItem("_p", btoa(password));
}
}

getPassword(): string {
return atob(localStorage.getItem("_p"))
}
}


export const lstore = new LStore();
File renamed without changes.
55 changes: 55 additions & 0 deletions frontend/src/gun/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import "gun/sea"
import {gun} from "./index";
import NotificationControl from "../lib/NotificationControl";
import {lstore} from "./LStore";

const user = gun.db.user();

class UserClass {

login(username: string, password: string) {
return user.auth(username, password, (ack) => {
if (ack.err !== undefined) {
NotificationControl.error("Cannot Login", ack.err)
lstore.setPassword(null) // in case auto login doesn't work
lstore.setUsername(null)
} else {
lstore.setUsername(username)
lstore.setPassword(password)
}
})
}

register(username: string, password: string) {
user.create(username, password, (ack) => {
if (ack.err !== undefined) {
NotificationControl.error("Cannot Register", ack.err)
}
})
}

isLoggedIn(): boolean {
if (lstore.getUsername() !== null && lstore.getPassword() !== null) {
// Perform auto login
this.login(lstore.getUsername(), lstore.getPassword())
return true;
}
return user.is
}

logout() {
lstore.setUsername(null);
lstore.setPassword(null);
user.leave()
}

delete(username: string, pass: string) {
lstore.setUsername(null);
lstore.setPassword(null);
user.delete(username, pass, (cb => {
console.log(cb)
}))
}
}

export const users = new UserClass();
52 changes: 46 additions & 6 deletions src/gun/index.ts → frontend/src/gun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,60 @@ import type {def} from "./PollGun";
import {pollGun} from "./PollGun";
import {commentGun} from "./CommentGun";
import {lstore} from "./LStore";
import {writable} from "svelte/store";
import NotificationControl from "../lib/NotificationControl";
type relayInfo = {status: "UP" | "DOWN", name: string, country: string, address: string, connected: boolean}

export const allRelays = writable([])


class PollMutations {
adminPubKey = "zgocnIYfpe41Rmocp1GI8OtN4rHVeG65T_V8QkhG0aA.rx0glUxtJUpxl1sc-AOh1tg3qhiykE7ektEHWkShFCA";
db = PollMutations.getGUN();
myRelays: Array<string> = [];
db;

constructor() {
this.defaultRelays();
}

private static getGUN() {
if (process.env.NODE_ENV === "development") {
return new GUN("http://localhost:8765/gun")
// return new GUN();
defaultRelays() {
if (import.meta.env.VITE_RELAY !== undefined) {
//@ts-ignore
const relays: Array<string> = (import.meta.env.VITE_RELAY as string).replaceAll(" ", "").split(",")
console.debug("Connection to: " + relays)
this.myRelays = relays
this.db = new GUN({peers: relays})
} else {
return new GUN('https://gun.tetrisiq.de/gun')
console.error("VITE_RELAY is not defined. Cannot connect to any network. You can only fix this in your deployment!")
this.db = new GUN();
}
}

setCustomRelays(newRelays: Array<relayInfo>) {
this.myRelays = []
newRelays.forEach(r => this.myRelays.push(r.address))
this.db = new GUN({peers: this.myRelays})
console.log(this.db)
NotificationControl.info("Changed relay server", "")
}


async getAllRelays() {
const allKeys = Object.keys(await this.db.get("peers"));
for (const key of allKeys) {
if (key !== "_") {
const host: relayInfo = await this.db.get(`peers/${key}`)
host.address = key;
host.connected = this.myRelays.includes(key)
allRelays.update(up => {
up.push(host);
return up;
})
}
}
}


async getReleaseMessage() {
this.db.get("message").once(async (message) => {
if (message !== undefined) {
Expand Down
Loading

0 comments on commit 0743fa9

Please sign in to comment.