Skip to content
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
7 changes: 1 addition & 6 deletions .github/commit-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ Optional body with more details.
## Prefixes
- [+] New feature or file added
- [-] File or feature removed
- [~] Modification or update
- [!] Bug fix
- [*] Refactor or cleanup
- [~] Modification or update or other
- [?] Tests
- [#] Configuration or build

## Examples
[+] Add user authentication module
[-] Remove deprecated payment API
[~] Update README with new install steps
[!] Fix crash on null pointer in parser
[*] Refactor database connection pool
2 changes: 1 addition & 1 deletion .github/workflows/La-Mira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: [ "main" ]

jobs:

build:
environment: production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
Expand Down
32 changes: 27 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,58 @@ package main
import (
"fmt"
"log"
"os"
"server/server"
)

func main() {
fmt.Println("Démarage du serveur")
fmt.Println("Démarage du serveur...")
cfg := server.ServerStart()
fmt.Println("Terminal du serveur :")
for {
var rep string
var path string
fmt.Print("$MIRA-Stream> ")
_, err := fmt.Scan(&rep)
if err != nil {
log.Fatalln("error input")
}
if rep == "-exit" {
if rep == "exit" {
break
}
if rep == "-vfolder" {
if rep == "vfolder" {
server.ChangeVFolder(&cfg)
fmt.Printf("After change : %+v\n", cfg)
continue
}
if rep == "-list" {
if rep == "list" {
server.TakeFolder(&cfg)
continue
}
if rep == "-config" {
if rep == "config" {
server.ViewConfig(cfg)
continue
}
if rep == "start" && cfg.StartStatut == 0 {
go server.SimpleHost(cfg)
cfg.StartStatut = 1
continue
}
if rep == "cd" {
_, err := fmt.Scan(&path)
if err != nil {
log.Fatalln("error cd")
}
os.Chdir(path)
cfg.Path, err = os.Getwd()
fmt.Printf("DEBUG CD : %v\n", cfg.Path)
continue
}
if rep == "ls" {
folder, _ := os.ReadDir(cfg.Path)
fmt.Printf("DEBUG LS : %+v\n", folder)
continue
}
fmt.Println("Command not found.")
}
}
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type conf struct {
Host string `toml:"host"`
} `toml:"server"`
Path string
StartStatut int
}

func LoadConf(path string) (conf, error) {
var cfg conf
_, err := toml.DecodeFile(path, &cfg)
cfg.Path, err = os.Getwd()
cfg.StartStatut = 0
return cfg, err
}

Expand Down
76 changes: 76 additions & 0 deletions server/server_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package server

import (
"encoding/json"
"fmt"
"net/http"
"os"
)

type Item struct {
ID int `json:"id"`
Name string `json:"name"`
}

type Folder struct {
Name string `json:"name"`
Type string `json:"type"`
}

var items = []Item{
{ID: 1, Name: "Item A"},
{ID: 2, Name: "Item B"},
}

func SearchInFolder() ([]Folder) {
entries, err := os.ReadDir(".")
if err != nil {
return nil
}
folders := make([]Folder, 0, len(entries))
for _, entry := range entries {
entryType := "file"
if entry.IsDir() {
entryType = "dir"
}
folders = append(folders, Folder{
Name: entry.Name(),
Type: entryType,
})
}
return folders
}

func itemsHandler(w http.ResponseWriter, r *http.Request) {
// Allow the Vite dev server to read API responses from the browser.
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")

if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusNoContent)
return
}

switch r.Method {
case http.MethodGet:
// On renvoie la liste en JSON
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(SearchInFolder()); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Erreur d'encodage JSON")
}
default:
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Méthode non autorisée"))
}
}

func SimpleHost(cfg conf) {
http.HandleFunc("/", itemsHandler)
fmt.Println("API lancer")
err := http.ListenAndServe(":8000", nil)
if err != nil {
fmt.Println("error server")
}
}
93 changes: 87 additions & 6 deletions web-client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,96 @@
import { useState } from 'react'
import { useState, useRef } from 'react'
import './App.css'

function HttpRequest() {
fetch('http://localhost:8000/')
.then((res) => {
if (!res.ok) throw new Error(`HTTP ${res.status}`)
return res.json()
})
.then((data) => {
console.log('JSON OK:', data)
})
.catch((err) => {
console.error('Erreur requête:', err)
})
}

function App() {
const [count, setCount] = useState(0)

const items = [
{ label: 'Ce connecter' },
{ label: 'Github' },
]

const sectionRef = useRef(null)

const handleScroll = () => {
sectionRef.current?.scrollIntoView({ behavior: 'smooth' })
}

return (
<section>
<div class="min-h-screen flex items-center justify-center text-4xl">
Hello Word
</div>
</section>
<div className="min-h-screen bg-zinc-950 text-zinc-100">
<header className="mx-auto flex w-full max-w-6xl items-center justify-between px-4 py-4">
<a href="/" className="text-xl font-semibold tracking-wide text-white">
MIRA Stream
</a>

<nav aria-label="Main navigation">
<ul className="flex items-center gap-5 text-sm">
{items.map((item) => (
<li key={item.label}>
<button
type="button"
onClick={handleScroll}
className="text-zinc-200 transition hover:text-white"
>
{item.label}
</button>
</li>
))}
</ul>
</nav>
</header>

<main>
<section className="mx-auto flex min-h-[calc(100vh-80px)] w-full max-w-6xl flex-col items-center justify-center px-4 text-center">
<h1 className="text-4xl font-bold md:text-5xl">
Bienvenue sur Mira Stream
</h1>

<button
type="button"
onClick={() => {
setCount((v) => v + 1)
HttpRequest()
}}
className="mt-6 rounded-md border border-zinc-600 bg-zinc-800 px-5 py-3 text-sm transition hover:bg-zinc-700"
>
Ce connecter au serveur
</button>
</section>

<section ref={sectionRef} className="mx-auto w-full max-w-6xl px-4 pb-20 pt-8">
<p className="text-center text-zinc-300">
Ton header est maintenant rendu par un composant React local, sans librairie externe.
</p>

<div className="mt-6 flex justify-center">
<button
type="button"
onClick={() => {
setCount((v) => v + 1)
HttpRequest()
}}
className="rounded-md border border-zinc-600 bg-zinc-800 px-4 py-2 text-sm transition hover:bg-zinc-700"
>
Tester API ({count})
</button>
</div>
</section>
</main>
</div>
)
}

Expand Down
21 changes: 21 additions & 0 deletions web-client/src/connection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";

export default function LoginPage() {
const goHome = () => {
window.location.hash = '#home'
}
return (
<div>
<button
type="button"
onClick={goHome}
className="fixed left-4 top-4 z-20 rounded-md border border-zinc-600 bg-zinc-900/90 px-4 py-2 text-sm text-zinc-100 backdrop-blur transition hover:bg-zinc-800"
>
Retour à l’accueil
</button>
<div className="min-h-screen bg-surface text-on-surface font-body selection:bg-primary-container selection:text-on-primary-container flex items-center justify-center p-6 overflow-hidden">
hello word
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion web-client/src/index.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:root {
--text: #6b6375;
--text-h: #08060d;
--bg: #2b2b2b;
--bg: #09090b;
--border: #e5e4e7;
--code-bg: #f4f3ec;
--accent: #aa3bff;
Expand Down