Skip to content

Commit

Permalink
atualizando guias, e persistencia de configurações
Browse files Browse the repository at this point in the history
  • Loading branch information
mundotv789123 committed Jan 4, 2025
1 parent ec672a5 commit 5ecc982
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 119 deletions.
119 changes: 23 additions & 96 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,44 @@
## Raspadmin Files
Um sistema para listagem de arquivos e reprodução de mídia.

## Tutorial de instalação
## Tutorial de instalação Docker

- Primeiro vamos clonar o repositório `raspadmin-files-react`.
- Para isso vamos executar os seguintes comandos.
Instale o docker

```bash
sudo apt install git
cd /srv
git clone https://github.com/mundotv789123/raspadmin-files-react.git
```sh
apt install curl
curl -sSL https://get.docker.com/ | CHANNEL=stable bash
```

- Após isso basta entrar na pasta e executar o script de instalação
Execute o container

```bash
cd raspadmin-files-react/
bash ./setup.sh
```

- Vamos configurar, para isso basta acessar o arquivo `docker-compose.yml`.

- Aqui você irá definir a pasta onde os arquivos serão armazenados
```yml
volumes:
- './:/app'
- '/mnt/files:/mnt/files'
```
- Exemplo caso você queira armazenar na pasta /root/arquivos
```yml
volumes:
- './:/app'
- '/root/arquivos:/mnt/files'
```
> Você só irá editar o caminho da primeira pasta.
- Você também pode definir uma senha de usuário, caso queira restringir o acesso
```sh
# Rodando container mínimo
docker run -d -p 8080:8080 -v ./files:/app/data/files --name raspadmin mundotv789123/raspadmin

```yml
environment:
NEXT_PUBLIC_API_URL: '/api'
API_AUTH: 'false'
API_USERNAME: 'admin'
API_PASSWORD: 'admin'
API_DIR: '/mnt/files'
```
# Rodando com usuário e senha
docker run -d -p 8080:8080 -v ./files:/app/data/files -e AUTH_ENABLED=true -e USERNAME=admin -e PASSWORD=admin --name raspadmin mundotv789123/raspadmin

- Basta mudar as seguintes linhas
```yml
API_AUTH: 'true'
API_USERNAME: 'seu usuário'
API_PASSWORD: 'sua senha aqui'
# Ativar geração de thumbnail em vídeos e músicas
docker run -d -p 8080:8080 -v ./files:/app/data/files -e MEDIA_THUMB=true --name raspadmin mundotv789123/raspadmin
```

- Após configurar basta reiniciar o projeto.
```bash
service raspadmin restart
```
## Docker compose

- Para acessar basta informar a seguinte url.
- `http://127.0.0.1/8080` ou `http://(endereço ip do servidor)/8080`.

> Lembrando que a primeira inicialização pode demorar um pouco, caso queira ver os logs de inicialização basta executar `docker-compose logs` ou `docker-compose logs -f` para visualizar em tempo real.
# Usando ssl com nginx (opicional)

- Aqui vamos configurar um proxy com nginx para ativar o ssl.
- Primeiro vamos instalar o nginx.

```bash
apt install nginx
```

- Após instalamos vamos criar um arquivo chamado `raspadmin.conf` na pasta `/etc/nginx/sites-available/`.
- Nesse arquivo vamos informar copiar os seguintes textos, lembrando de mudar o `<dominio>` para o domínio que você deseja usar.

```conf
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name <dominio>;
location / {
proxy_pass http://127.0.0.1:8080;
}
# informe aqui seus arquivos ssl
ssl_certificate /etc/nginx/certificates/certificate.cert;
ssl_certificate_key /etc/nginx/certificates/certificate.key;
}
```

- Caso não queira usar certificado ssl mas deseja usar a porta padrão 80 basta copiar esse texto no lugar do texto a cima.
Crie uma pasta e baixe o arquivo docker-compose.yml

```conf
server {
listen 80;
listen [::]:80;
server_name <dominio>;
```sh
mkdir /srv/raspadmin
cd /srv/raspadmin

location / {
proxy_pass http://127.0.0.1:8080;
}
}
curl -o docker-compose.yml https://raw.githubusercontent.com/mundotv789123/raspadmin-files-react/refs/heads/main/docker-compose.yml
```

- Agora vamos habilitar o site e reiniciar o nginx
Em seguida basta executar o container

```bash
ln -s /etc/nginx/sites-available/raspadmin.conf /etc/nginx/sites-enabled/raspadmin.conf
systemctl restart nginx
```sh
docker compose up -d
```

## Pronto! seu site foi configurado e está pronto para funcionar!
### Para acessar o site basta entrar no link http://localhost:8080
43 changes: 20 additions & 23 deletions src/components/AudioPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import PlayList from "./PlayList";
import Range from "../../elements/range";
import { numberClockTime, srcToFileName } from "../../helpers/ConverterHelper";
import { getErrorMessage } from "@/services/exceptions/FilesErros";
import { useLocalStorage } from "@/helpers/HooksHelper";

interface AudioControl {
muted: boolean,
random: boolean,
playing: boolean,
playlistOpened: boolean,
hideTitle: boolean
hideTitle: boolean,
volume: number
}

interface AudioProps {
duration: number,
currentTime: number,
volume: number
currentTime: number
}

interface PropsInterface {
Expand All @@ -33,24 +34,28 @@ export default function AudioPlayer(props: PropsInterface) {

const playlist = props.playlist;

const [controls, setControls] = useState<AudioControl>({
const [controls, setControls] = useLocalStorage<AudioControl>("audio-settings", {
muted: false,
random: false,
playing: false,
playlistOpened: false,
hideTitle: false
hideTitle: false,
volume: .5
});

const [audioProps, setAudioProps] = useState<AudioProps>({
duration: 0,
currentTime: 0,
volume: 0
currentTime: 0
});

const audioDuration = useMemo(() => numberClockTime(audioProps.duration), [audioProps.duration]);
const audioCurrentTime = useMemo(() => numberClockTime(audioProps.currentTime), [audioProps.currentTime]);
const progressPercent = useMemo(() => audioProps.duration == 0 ? 0 : (audioProps.currentTime * 100 / audioProps.duration), [audioProps.currentTime]);
const currentPlayList = useMemo(() => controls.random ? playlist.map(a => a).sort(() => Math.random() - 0.5) : playlist, [controls.random, playlist]);
const progressPercent = useMemo(() =>
audioProps.duration == 0 ? 0 : (audioProps.currentTime * 100 / audioProps.duration)
, [audioProps.currentTime, audioProps.duration]);
const currentPlayList = useMemo(() =>
controls.random ? playlist.map(a => a).sort(() => Math.random() - 0.5) : playlist
, [controls.random, playlist]);

const [errorText, setErrorText] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
Expand All @@ -62,7 +67,7 @@ export default function AudioPlayer(props: PropsInterface) {
audioElement.current!.currentTime = 0;
else
setSrc(props.src);
}, [props.src])
}, [props.src, src])

useEffect(() => {
setLoading(true);
Expand All @@ -78,10 +83,8 @@ export default function AudioPlayer(props: PropsInterface) {
setErrorText(null);
loadMediaSession();

const volume = getSessionVolume();
setAudioProps((prev) => ({ ...prev, volume, duration: audioElement.current!.duration }));

audioElement.current!.volume = controls.muted ? 0 : volume / 100;
setAudioProps((prev) => ({ ...prev, duration: audioElement.current!.duration }));
audioElement.current!.volume = controls.muted ? 0 : controls.volume;

setLoading(false);
}
Expand Down Expand Up @@ -129,8 +132,7 @@ export default function AudioPlayer(props: PropsInterface) {
function updateAudioVolume(percent: number) {
if (!controls.muted)
audioElement.current!.volume = percent / 100;
localStorage.setItem('audio_volume', percent.toFixed(2));
setAudioProps((prev) => ({ ...prev, volume: percent }));
setControls((prev) => ({ ...prev, volume: audioElement.current!.volume }));
return true;
}

Expand Down Expand Up @@ -167,14 +169,9 @@ export default function AudioPlayer(props: PropsInterface) {
setSrc(src);
}

function getSessionVolume(): number {
const volume = localStorage.getItem('audio_volume') ? Number(localStorage.getItem('audio_volume')) : 50;
return volume < 0 ? 0 : volume;
}

function updateMuted() {
const isMuted = !controls.muted;
audioElement.current!.volume = isMuted ? 0 : audioProps.volume / 100;
audioElement.current!.volume = isMuted ? 0 : controls.volume;
setControls((prev) => ({ ...prev, muted: isMuted }));
}

Expand Down Expand Up @@ -236,7 +233,7 @@ export default function AudioPlayer(props: PropsInterface) {
<FontAwesomeIcon icon={controls.muted ? faVolumeMute : faVolumeUp} style={{ fontSize: '16pt' }} />
</ControlButton>
<VolumeProgress>
<Range percent={audioProps.volume} onInput={updateAudioVolume} live={true} step={'0.1'} />
<Range percent={controls.volume * 100} onInput={updateAudioVolume} live={true} step={'0.1'} />
</VolumeProgress>
</VolumeControl>
<ControlButton onClick={updateHideTitle}>
Expand Down
23 changes: 23 additions & 0 deletions src/helpers/HooksHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState, useEffect, Dispatch, SetStateAction } from 'react';

export function useLocalStorage<T>(key: string, initialValue: T): [T, Dispatch<SetStateAction<T>>] {
const [state, setState] = useState<T>(() => {
try {
const storedValue = localStorage.getItem(key);
return storedValue ? JSON.parse(storedValue) : initialValue;
} catch (error) {
console.error("Erro ao acessar localStorage:", error);
return initialValue;
}
});

useEffect(() => {
try {
localStorage.setItem(key, JSON.stringify(state));
} catch (error) {
console.error("Erro ao atualizar localStorage:", error);
}
}, [key, state]);

return [state, setState];
}

0 comments on commit 5ecc982

Please sign in to comment.