Skip to content

Commit

Permalink
AUDIO modified go
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandanzl committed Feb 2, 2025
1 parent 4eedf88 commit 84649af
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 29 deletions.
31 changes: 13 additions & 18 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ version: '3'
tasks:
help:
cmds:
- echo ""
- task --list-all
aliases: [h, -h]

yarn_install:
dir: assets
Expand Down Expand Up @@ -67,17 +68,17 @@ tasks:
- docker push ghcr.io/stefandanzl/cloudr:latest

push_docker_raspi:
cmds:
cmds:
- docker push ghcr.io/stefandanzl/cloudr:raspi

go_run:
cmds:
- go run .

firefox:
dir: "C:/Program Files/Mozilla Firefox"
browser:
cmds:
- ./firefox.exe --private-window http://localhost:5212
- cmd: cmd.exe /c start http://localhost:5212
platforms: [windows]

finished:
cmds:
Expand All @@ -87,15 +88,9 @@ tasks:
cmds:
- "rclone mount devcloudr:/ R: --vfs-cache-mode full --volname Cloudr"






#######
h:
cmds:
- task --list-all

run_wsl:
cmds:
- "'C:/Program Files/Mozilla Firefox/firefox.exe' --private-window http://localhost:5214"
Expand All @@ -105,29 +100,29 @@ tasks:
run:
dir: dev
cmds:
- task: firefox
- cmd: ./cloudr.exe
platforms: [windows]
- cmd: ./cloudr
platforms: [linux]


build-run:
cmds:
- cmd: task build_windows
platforms: [windows]
- cmd: task build_linux
platforms: [linux]
- task: firefox
- task: run-build
- task: browser
- task: run

# Local Development tasks
dev:
cmds:
- task: yarn_build
- task: zip
- task: firefox
- task: finished
- task: go_run
- task: browser
# - task: finished
- task: run

fulll:
cmds:
Expand Down
47 changes: 39 additions & 8 deletions assets/src/component/FileManager/MusicPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
import { withTranslation } from "react-i18next";
import MediaSession from '@mebtte/react-media-session';
import "./MusicPlayer.css"; // Import your CSS file for styling
import API from "../../middleware/Api";



const styles = (theme) => ({
Expand Down Expand Up @@ -93,6 +95,7 @@ class MusicPlayerComponent extends Component {
looptype: 0,
selectedSpeed: initialSpeed,
// New settings state
saveIntervalId: null,
audioSettings: {
remainingTime: 120,
speedFactor: 1,
Expand All @@ -117,21 +120,36 @@ class MusicPlayerComponent extends Component {
},
};
this.myAudioRef = React.createRef();

this.initSettings();
}

initSettings = async () => {
// Load initial settings
this.loadUserSettings();

// Start periodic saving - using the interval from settings or default to 10 seconds
const saveIntervalId = setInterval(() => {
this.saveUserSettings();
}, (this.state.audioSettings.saveInterval || 10) * 1000);

// Store the interval ID in state
this.setState({ saveIntervalId });
}

loadUserSettings = async () => {
console.log("loadUserSettings");
try {
const response = await API.get("/user/setting");
if (response.data.audio) {
console.log(response)
if ("audio" in response.data) {
this.setState({ audioSettings: response.data.audio });
if (response.data.audio.speedFactor) {
if ("speedfactor" in response.data.audio) {
this.setState({ selectedSpeed: parseFloat(response.data.audio.speedFactor) });
if (this.myAudioRef.current) {
this.myAudioRef.current.playbackRate = parseFloat(response.data.audio.speedFactor);
if (response.data.audio.last) {
const playbackData = response.data.audio.last.filter((item) => { item.src === this.state.items[this.state.currentIndex]?.src });
if (response.data.audio.history) {
const playbackData = response.data.audio.history.filter((item) => { item.src === this.state.items[this.state.currentIndex]?.src });
if (playbackData.length > 0) {
const thisLastPlayed = playbackData[0]
this.myAudioRef.current.currentTime = parseFloat(thisLastPlayed.timestamp);
Expand All @@ -149,6 +167,7 @@ class MusicPlayerComponent extends Component {
}

saveUserSettings = async () => {
console.log("saveUserSettings")
if (!this.myAudioRef.current || !this.state.items[this.state.currentIndex]) return;

const currentAudio = this.state.items[this.state.currentIndex];
Expand All @@ -175,19 +194,23 @@ class MusicPlayerComponent extends Component {

const updatedSettings = {
...this.state.audioSettings,
last: updatedLast
history: updatedLast
};

try {
await API.post("/user/setting", {
audio: updatedSettings
});
API.patch("/user/setting/audio", {
audio: updatedSettings,
})
this.setState({ audioSettings: updatedSettings });
} catch (error) {
console.error('Failed to save audio settings:', error);
}
}

// async UNSAFE_componentWillMount() {
// await this.loadUserSettings();
// }

UNSAFE_componentWillReceiveProps = (nextProps) => {
const items = [];
let firstOne = 0;
Expand Down Expand Up @@ -276,6 +299,9 @@ class MusicPlayerComponent extends Component {
if (this.myAudioRef.current) {
this.bindEvents(this.myAudioRef.current);
}

// doesnt actually run?

}
componentDidUpdate() {
if (this.myAudioRef.current) {
Expand All @@ -284,6 +310,11 @@ class MusicPlayerComponent extends Component {
}
componentWillUnmount() {
this.unbindEvents(this.myAudioRef.current);

// Clear the save interval
if (this.state.saveIntervalId) {
clearInterval(this.state.saveIntervalId);
}
}

bindEvents = (ele) => {
Expand Down
26 changes: 23 additions & 3 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func init() {

// User personalized configuration fields UserOption 用户个性化配置字段
type UserOption struct {
ProfileOff bool `json:"profile_off,omitempty"`
PreferredTheme string `json:"preferred_theme,omitempty"`
PdfSettings PdfSettings `json:"pdf,omitempty"`
ProfileOff bool `json:"profile_off,omitempty"`
PreferredTheme string `json:"preferred_theme,omitempty"`
PdfSettings PdfSettings `json:"pdf,omitempty"`
AudioSettings AudioSettings `json:"audio,omitempty"`
}

// PDF settings
Expand All @@ -67,6 +68,25 @@ type PdfSettings struct {
ChangePrompt bool `json:"changePrompt"`
}

// AudioSettings represents user audio playback preferences and history
type AudioSettings struct {
RemainingTime int `json:"remainingTime"` // Time threshold in seconds
SpeedFactor float64 `json:"speedFactor"` // Playback speed multiplier
KeepHistory int `json:"keepHistory"` // Number of entries to keep in history
SaveInterval int `json:"saveInterval"` // How often to save in seconds
History []PlaybackHistory `json:"history"`
}

// PlaybackHistory represents a single audio playback session entry
type PlaybackHistory struct {
Title string `json:"title"` // Audio file name/title
Status string `json:"status"` // 'started' or 'ended'
Src string `json:"src"` // Source path/URL of the audio
Speed float64 `json:"speed"` // Playback speed used
Timestamp float64 `json:"timestamp"` // Last playback position in seconds
Total float64 `json:"total"` // Total duration of audio
}

// Get the user's root directory Root 获取用户的根目录
func (user *User) Root() (*Folder, error) {
var folder Folder
Expand Down
2 changes: 2 additions & 0 deletions routers/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ func UpdateOption(c *gin.Context) {
subService = &user.ThemeChose{}
case "pdf":
subService = &user.PdfSettingsService{}
case "audio":
subService = &user.AudioSettingsService{}
default:
subService = &user.ChangerNick{}
}
Expand Down
13 changes: 13 additions & 0 deletions service/user/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ func (service *PdfSettingsService) Update(c *gin.Context, user *model.User) seri
return serializer.Response{}
}

type AudioSettingsService struct {
AudioSettings model.AudioSettings `json:"audio"`
}

func (service *AudioSettingsService) Update(c *gin.Context, user *model.User) serializer.Response {
user.OptionsSerialized.AudioSettings = service.AudioSettings
if err := user.UpdateOptions(); err != nil {
return serializer.DBErr("Failed to update user preferences", err)
}

return serializer.Response{}
}

// Update theme settings Update 更新主题设定
func (service *ThemeChose) Update(c *gin.Context, user *model.User) serializer.Response {
user.OptionsSerialized.PreferredTheme = service.Theme
Expand Down

0 comments on commit 84649af

Please sign in to comment.