Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stoream]: pin login support, some bug fixes #41

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode/
.idea/
*.gz
*.zip
*.zip
.fake
2 changes: 1 addition & 1 deletion publish.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ let Exec: string -> CommandResult =
let PublishWebUI () =
Log.info "Building WebUI module..."

(Exec $"cd stoream-webui && pnpm build")
(Exec $"cd stoream-webui && pnpm install && pnpm build")
<|> (Failure, (fun result -> Log.error $"{result.StandardError}"))
<|> (Success, (fun result -> Log.info $"DONE"))
|> ignore
Expand Down
1 change: 1 addition & 0 deletions stoream-engine/src/Config/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ open FSharp.Data
type Config =
JsonProvider<"""
{
"PIN": "294538",
"Account": {
"Username": "admin",
"Password": "admin"
Expand Down
29 changes: 29 additions & 0 deletions stoream-engine/src/Logger/Logger.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
(* Copyright (c) 2024 The X-Files Research Institute
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Stoream nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)

module Stoream.Engine.Logger.StoreamLogger

open System
Expand Down
65 changes: 65 additions & 0 deletions stoream-engine/src/PIN/PIN.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(* Copyright (c) 2024 The X-Files Research Institute
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Stoream nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)

module Stoream.Engine.PIN

open System
open Suave
open Suave.Filters
open Suave.Successful
open Suave.Operators
open Config
open API.Constraint
open API.Response
open Stoream.Engine.Logger.StoreamLogger

type PIN() =

(* Get the configuration file loaded at startup by the Stoream.Engine.Config module.
* SEE: Stoream.Engine.Config *)
static member inline public CONFIG = CONFIG.Pin

(* Implementing the API interface indicates that this type is an API service *)
interface IGetAPI with
static member public App = PIN.App

static member public App =
path "/pin" >=> GET >=> request PIN.PIN

static member private PIN (request: HttpRequest) =
StoreamLogger.Info $"request {PIN}"

request.queryParamOpt("value").Value
|> snd
|> _.Value
|> fun pin ->
if pin = PIN.CONFIG.ToString() then
Response.OK ()
else
Response.ERROR (ArgumentException $"Invalid PIN {pin}")
4 changes: 3 additions & 1 deletion stoream-engine/src/Server/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ open Suave.Filters
open Suave.Operators
open Config
open Account
open PIN
open WebUI
open Stoream.Engine.Storage.Storage

Expand Down Expand Up @@ -68,7 +69,8 @@ type Server () =
(* Please add new services here. *)
WebUI.App
Account.App
Storage.GetApp ])
Storage.GetApp
PIN.App ])
POST
>=> fun context ->
context
Expand Down
1 change: 1 addition & 0 deletions stoream-engine/stoream-engine.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="src/Config/Config.fs" />
<Compile Include="src/API/API.fs" />
<Compile Include="src/API/Response.fs" />
<Compile Include="src/PIN/PIN.fs" />
<Compile Include="src/Account/Account.fs" />
<Compile Include="src/WebUI/WebUI.fs" />
<Compile Include="src/Storage/Secure.fs" />
Expand Down
1 change: 1 addition & 0 deletions stoream-engine/stoream-engine.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"PIN": "294538",
"Account": {
"Username": "admin",
"Password": "21232f297a57a5a743894a0e4a801fc3"
Expand Down
37 changes: 22 additions & 15 deletions stoream-webui/src/components/DownloadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ interface DownloadFileProps {

const DownloadFile: React.FC<DownloadFileProps> = ({ file, modalState, setModalState }) => {
const [downloadingWaitState, setDownloadingWaitState] = useDisclosure(false);

const download = async () => {
setDownloadingWaitState.open()
const link = URL.createObjectURL(await Request.$$File.cat(file))
const download = document.createElement("a")
download.href = link
download.download = file.filename
setDownloadingWaitState.open()
download.click()
URL.revokeObjectURL(link)
setModalState.close()
download.remove()
setDownloadingWaitState.close()
}

return (
<>
<Modal
Expand All @@ -58,27 +73,19 @@ const DownloadFile: React.FC<DownloadFileProps> = ({ file, modalState, setModalS
backgroundOpacity: 0.55,
blur: 3,
}}>
<Box pos="relative">
<LoadingOverlay visible={downloadingWaitState} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} />
</Box>
<LoadingOverlay visible={downloadingWaitState} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} />
<List>
<List.Item>File name: {file.filename}</List.Item>
<List.Item>File path: {file.filepath}</List.Item>
<List.Item>File size: {stringOfFileSize(file.filesize)}</List.Item>
</List>
<Center>
<Button mt="lg" leftSection={<IconDownload style={{ width: rem(14), height: rem(14) }} />} onClick={async () => {
const link = URL.createObjectURL(await Request.$$File.cat(file))
const download = document.createElement("a")
download.href = link
download.download = file.filename
setDownloadingWaitState.open()
download.click()
URL.revokeObjectURL(link)
setDownloadingWaitState.close()
setModalState.close()
download.remove()
}}> Click to download </Button>
<Button
mt="lg"
c="dark" bg="orange"
leftSection={<IconDownload style={{ width: rem(14), height: rem(14) }} />}
onClick={async () => await download()}
> Click to download </Button>
</Center>
</Modal>
</>
Expand Down
2 changes: 1 addition & 1 deletion stoream-webui/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import { Avatar, Card, Container, Drawer, Grid, GridCol, Group, Skeleton, Space, Stack, Tooltip } from "@mantine/core";
import { Avatar, Card, Container, Drawer, Grid, GridCol, Group, Skeleton, Space, Stack, Text, Tooltip } from "@mantine/core";
import { useDisclosure } from '@mantine/hooks';
import About from "./About";
import FileTypes from "./FileTypes";
Expand Down
42 changes: 42 additions & 0 deletions stoream-webui/src/components/PreviewFile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// Copyright (c) 2024 The X-Files Research Institute
///
/// All rights reserved.
///
/// Redistribution and use in source and binary forms, with or without modification,
/// are permitted provided that the following conditions are met:
///
/// * Redistributions of source code must retain the above copyright notice,
/// this list of conditions and the following disclaimer.
/// * Redistributions in binary form must reproduce the above copyright notice,
/// this list of conditions and the following disclaimer in the documentation
/// and/or other materials provided with the distribution.
/// * Neither the name of Stoream nor the names of its contributors
/// may be used to endorse or promote products derived from this software
/// without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
/// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
/// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
/// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
/// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
/// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import React from "react"

interface PreviwFileProps {

}

const PreviewFile: React.FC<PreviwFileProps> = () => {
return (
<>
</>
)
}

export default PreviewFile
5 changes: 2 additions & 3 deletions stoream-webui/src/components/UploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const UploadFile: React.FC<UploadFileProps> = ({ breadcrumbs, setBreadcrumbs, se
const upload = async () => {
const data = new FormData()
data.append(uploadFile?.name as string, uploadFile as File)
setUploadingWaitState.open()

await
Request.$$File
Expand Down Expand Up @@ -95,9 +96,7 @@ const UploadFile: React.FC<UploadFileProps> = ({ breadcrumbs, setBreadcrumbs, se
}}
w={"auto"}
>
<Box pos="relative">
<LoadingOverlay visible={uploadingWaitState} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} />
</Box>
<LoadingOverlay visible={uploadingWaitState} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} />
<Fieldset legend="Upload File">
<FileInput
value={uploadFile}
Expand Down
13 changes: 11 additions & 2 deletions stoream-webui/src/model/Config.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
type t = {engine: string}

@val @scope(("window", "location"))
external engine: string = "host"
external host: string = "host"

let config: t = {engine: engine}
@val @scope(("window", "localStorage"))
external devMode: string = "devMode"

let config: t = {
engine: if devMode == "true" {
"http://localhost:9993"
} else {
""
},
}
30 changes: 30 additions & 0 deletions stoream-webui/src/model/Pin.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// Copyright (c) 2024 The X-Files Research Institute
///
/// All rights reserved.
///
/// Redistribution and use in source and binary forms, with or without modification,
/// are permitted provided that the following conditions are met:
///
/// * Redistributions of source code must retain the above copyright notice,
/// this list of conditions and the following disclaimer.
/// * Redistributions in binary form must reproduce the above copyright notice,
/// this list of conditions and the following disclaimer in the documentation
/// and/or other materials provided with the distribution.
/// * Neither the name of Stoream nor the names of its contributors
/// may be used to endorse or promote products derived from this software
/// without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
/// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
/// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
/// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
/// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
/// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@genType.as("Pin")
type t = string
Loading
Loading